OpenHarmony打包时提示detecting c compiler abi info - failed
OpenHarmony打包时提示detecting c compiler abi info - failed 新建项目,runtimeOS切换为openharmony,切换BiSheng为Original,无法打包成功
Exceptions happened while executing C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\build-tools\cmake\bin\cmake.exe -HC:\Users\Admin\DevEcoStudioProjects\MyApplication\Library1\src\main\cpp -BC:\Users\Admin\DevEcoStudioProjects\MyApplication\Library1\.cxx\default\default\debug\arm64-v8a -DOHOS_ARCH=arm64-v8a -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Admin\DevEcoStudioProjects\MyApplication\Library1\build\default\intermediates\cmake\default\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -DOHOS_SDK_NATIVE=C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native -DCMAKE_SYSTEM_NAME=OHOS -DCMAKE_OHOS_ARCH_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\build\cmake\ohos.toolchain.cmake -GNinja -DCMAKE_MAKE_PROGRAM=C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\build-tools\cmake\bin\ninja.exe -DCMAKE_FIND_ROOT_PATH=C:\Users\Admin\DevEcoStudioProjects\MyApplication\Library1\.cxx\default\default\debug\hvigor\arm64-v8a -DPACKAGE_FIND_FILE=C:\Users\Admin\DevEcoStudioProjects\MyApplication\Library1\.cxx\default\default\debug\hvigor\arm64-v8a\summary.cmake --no-warn-unused-cli -DCMAKE_CXX_FLAGS=--std=c++11.
Not searching for unused variables given on the command line.
-- The C compiler identification is Clang 15.0.4
-- The CXX compiler identification is Clang 15.0.4
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm/bin/clang.exe
-- Check for working C compiler: C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm/bin/clang.exe - broken
CMake Error at C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/build-tools/cmake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: 'C:/Users/Admin/DevEcoStudioProjects/MyApplication/Library1/.cxx/default/default/debug/arm64-v8a/CMakeFiles/CMakeScratch/TryCompile-3jnczn'
Run Build Command(s): C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\build-tools\cmake\bin\ninja.exe -v cmTC_6af85
[1/2] C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\llvm\bin\clang.exe --target=aarch64-linux-ohos --gcc-toolchain=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm --sysroot=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/sysroot -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -D__MUSL__ -fPIE -MD -MT CMakeFiles/cmTC_6af85.dir/testCCompiler.c.o -MF CMakeFiles\cmTC_6af85.dir\testCCompiler.c.o.d -o CMakeFiles/cmTC_6af85.dir/testCCompiler.c.o -c C:/Users/Admin/DevEcoStudioProjects/MyApplication/Library1/.cxx/default/default/debug/arm64-v8a/CMakeFiles/CMakeScratch/TryCompile-3jnczn/testCCompiler.c
clang: warning: argument unused during compilation: '--gcc-toolchain=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm' [-Wunused-command-line-argument]
[2/2] C:\Windows\system32\cmd.exe /C "cd . && C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\llvm\bin\clang.exe --target=aarch64-linux-ohos --gcc-toolchain=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm --sysroot=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/sysroot -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -D__MUSL__ --rtlib=compiler-rt -fuse-ld=lld -Wl,--build-id=sha1 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -lunwind -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,--gc-sections CMakeFiles/cmTC_6af85.dir/testCCompiler.c.o -o cmTC_6af85 -lm && cd ."
FAILED: cmTC_6af85
C:\Windows\system32\cmd.exe /C "cd . && C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\llvm\bin\clang.exe --target=aarch64-linux-ohos --gcc-toolchain=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm --sysroot=C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/sysroot -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -D__MUSL__ --rtlib=compiler-rt -fuse-ld=lld -Wl,--build-id=sha1 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -lunwind -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,--gc-sections CMakeFiles/cmTC_6af85.dir/testCCompiler.c.o -o cmTC_6af85 -lm && cd ."
clang: error: unable to execute command: Couldn't execute program 'C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm/bin/ld.lld.exe': Unknown error (0xD8)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
undefined
4 回复
C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\llvm\bin\ld.lld.exe损坏,重新装SDK后恢复正常
6
OpenHarmony打包报此错误,多因NDK工具链不匹配或CMake配置错误。检查:
- 确认
ohos-sdk中native目录下ndk版本与build-profile.json5中abiFilters一致。 - 若使用Clang,需指定
CMAKE_C_COMPILER为clang,并设置CMAKE_SYSTEM_NAME=OHOS。 - 清理
build目录后重新构建。
该提示表示CMake无法辨别C编译器ABI,需确保环境变量OHOS_SDK与PATH正确指向SDK原生工具链。
问题分析
从日志来看,CMake 检测编译器 ABI 时失败,关键错误是:
clang: error: unable to execute command: Couldn't execute program 'C:/Users/Admin/AppData/Local/OpenHarmony/Sdk/20/native/llvm/bin/ld.lld.exe': Unknown error (0xD8)
这个 0xD8 错误通常是 Windows 系统无法加载该可执行文件,常见原因有:
ld.lld.exe文件缺失、损坏,或被杀毒软件/系统策略拦截。- OpenHarmony SDK 的 native 工具链路径中包含空格或过长路径,导致命令执行异常(本例路径无空格,但可检查)。
- 系统缺少必要的 Visual C++ 运行库(如
vcruntime140.dll等),导致ld.lld.exe无法启动。 - 权限不足,cmake/ninja 调用链接器时被拒绝。
建议按顺序排查:
- 确认
C:\Users\Admin\AppData\Local\OpenHarmony\Sdk\20\native\llvm\bin\ld.lld.exe存在且可正常双击运行(若报错则重装 SDK)。 - 暂时关闭杀毒软件或添加白名单,然后重新构建。
- 安装/修复 Visual C++ Redistributable(x64)。
- 尝试以管理员身份运行 DevEco Studio,或清理
.cxx目录后重新同步。
如果这些都不能解决,请检查 OpenHarmony SDK 版本是否与 DevEco Studio 匹配,或重新下载完整 SDK。
