HarmonyOS鸿蒙Next中CMake构建工程配置编译工具链失败

HarmonyOS鸿蒙Next中CMake构建工程配置编译工具链失败

咨询描述: CMake Error at /home/fy/ohos-sdk/native/build-tools/cmake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):

The C compiler

"/home/fy/ohos-sdk/native/llvm/bin/clang"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/fy/third_party/gdal/geos-3.7.3/CMakeFiles/CMakeScratch/TryCompile-GjoMTG

Run Build Command(s): /home/fy/ohos-sdk/native/build-tools/cmake/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_d043e/fast

/usr/bin/make -f CMakeFiles/cmTC_d043e.dir/build.make CMakeFiles/cmTC_d043e.dir/build

make[1]: Entering directory /home/fy/third_party/gdal/geos-3.7.3/CMakeFiles/CMakeScratch/TryCompile-GjoMTG

Building C object CMakeFiles/cmTC_d043e.dir/testCCompiler.c.o

/home/fy/ohos-sdk/native/llvm/bin/clang -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,–noexecstack -Wformat -Werror=format-security -D__MUSL__ -o CMakeFiles/cmTC_d043e.dir/testCCompiler.c.o -c /home/fy/third_party/gdal/geos-3.7.3/CMakeFiles/CMakeScratch/TryCompile-GjoMTG/testCCompiler.c

/home/fy/ohos-sdk/native/llvm/bin/clang: line 1: clang-15: command not found

make[1]: *** [CMakeFiles/cmTC_d043e.dir/build.make:78: CMakeFiles/cmTC_d043e.dir/testCCompiler.c.o] Error 127

make[1]: Leaving directory /home/fy/third_party/gdal/geos-3.7.3/CMakeFiles/CMakeScratch/TryCompile-GjoMTG

make: *** [Makefile:127: cmTC_d043e/fast] Error 2

-rwxrwxrwx 1 root root 8 Jan 1 2001 clang

-rwxrwxrwx 1 root root 5 Jan 1 2001 clang++

咨询场景描述:

工程机版本:(如:NOH-AN00 204.0.0.65(SP1C00E67R1P12))

DevEco Studio版本:(如:DevEco Studio 4.0.3.600)

SDK版本:(如:OpenHarmony 4.0.10.10)


更多关于HarmonyOS鸿蒙Next中CMake构建工程配置编译工具链失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

clang环境问题,建议IDE更新clang或整个llvm工具链

linux环境可直接使用 sudo apt install g++

建议对环境进行整体更新

sudo apt-get update
sudo apt-get install default-jdk genext2fs u-boot-tools mtools mtd-utils scons git-lfs ruby python3.10 python3.10-distutils swig linux-libc-dev gcc-multilib binutils-dev g++ ninja-build

其中python需确认3.10是否需要更新,不需要更新python可以去掉python3.10 python3.10-distutils

更多关于HarmonyOS鸿蒙Next中CMake构建工程配置编译工具链失败的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,CMake构建工程配置编译工具链失败,可能是由于工具链路径未正确设置或CMake版本不兼容。检查CMakeLists.txtCMAKE_TOOLCHAIN_FILE的路径是否正确指向鸿蒙的工具链文件。确保使用的CMake版本与鸿蒙Next的要求一致。若问题依旧,可尝试清理CMake缓存并重新生成构建文件。

从错误信息看,主要问题是clang工具链配置有问题。具体表现为:

  1. 错误显示clang-15: command not found,说明SDK中的clang工具链没有正确安装或配置
  2. 查看文件权限显示clang和clang++文件大小异常(只有8字节和5字节),这显然不是完整的编译器二进制文件

建议检查以下方面:

  1. 确认SDK安装是否完整,特别是native/llvm部分
  2. 检查环境变量PATH是否正确包含SDK的llvm/bin路径
  3. 尝试重新安装或更新SDK,确保工具链文件完整

这是典型的工具链文件损坏或配置错误导致的编译问题,需要重新获取完整的工具链文件。

回到顶部