目录

huks Native接口编译报错问题

问题场景

使用huks密钥库的c接口生成密钥时编译报错,错误信息如下:

hvigor ERROR: Failed: har1withso:default@BuildNativeWithNinja… 
hvigor ERROR: Tools execution failed. 
Command failed with exit code 1: C:\HarmonyOS\sdk\default\base\native\build-tools\cmake\bin\ninja.exe -C C:\my\harmonyos-project\hos1230\har1withso.cxx\default\default\arm64-v8a 
ninja: Entering directory `C:\my\harmonyos-project\hos1230\har1withso.cxx\default\default\arm64-v8a’ 
[1/2] Building CXX object CMakeFiles/har1withso.dir/hello.cpp.o 
clang++: warning: argument unused during compilation: ‘–gcc-toolchain=C:/HarmonyOS/sdk/default/base/native/llvm’ [-Wunused-command-line-argument] 
[2/2] Linking CXX shared library C:\my\harmonyos-project\hos1230\har1withso\build\default\intermediates\cmake\default\obj\arm64-v8a\libhar1withso.so 
FAILED: C:/my/harmonyos-project/hos1230/har1withso/build/default/intermediates/cmake/default/obj/arm64-v8a/libhar1withso.so 
cmd.exe /C “cd . && C:\HarmonyOS\sdk\default\base\native\llvm\bin\clang++.exe --target=aarch64-linux-ohos --gcc-toolchain=C:/HarmonyOS/sdk/default/base/native/llvm --sysroot=C:/HarmonyOS/sdk/default/base/native/sysroot -fPIC -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,–noexecstack -Wformat -Werror=format-security -D__MUSL__ -O0 -g -fno-limit-debug-info --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 -shared -Wl,-soname,libhar1withso.so -o C:\my\harmonyos-project\hos1230\har1withso\build\default\intermediates\cmake\default\obj\arm64-v8a\libhar1withso.so CMakeFiles/har1withso.dir/hello.cpp.o -lace_napi.z -lm && cd .” 
ld.lld: error: undefined symbol: OH_Huks_InitParamSet 
 
referenced by hello.cpp:7 (C:/my/harmonyos-project/hos1230/har1withso/src/main/cpp/hello.cpp:7) 
CMakeFiles/har1withso.dir/hello.cpp.o:(InitParamSet(OH_Huks_ParamSet**, OH_Huks_Param const*, unsigned int)) 
ld.lld: error: undefined symbol: OH_Huks_AddParams 
 
referenced by hello.cpp:11 (C:/my/harmonyos-project/hos1230/har1withso/src/main/cpp/hello.cpp:11) 
CMakeFiles/har1withso.dir/hello.cpp.o:(InitParamSet(OH_Huks_ParamSet**, OH_Huks_Param const*, unsigned int)) 
ld.lld: error: undefined symbol: OH_Huks_FreeParamSet 
 
referenced by hello.cpp:13 (C:/my/harmonyos-project/hos1230/har1withso/src/main/cpp/hello.cpp:13) 
CMakeFiles/har1withso.dir/hello.cpp.o:(InitParamSet(OH_Huks_ParamSet**, OH_Huks_Param const*, unsigned int)) 
referenced by hello.cpp:18 (C:/my/harmonyos-project/hos1230/har1withso/src/main/cpp/hello.cpp:18) 
CMakeFiles/har1withso.dir/hello.cpp.o:(InitParamSet(OH_Huks_ParamSet**, OH_Huks_Param const*, unsigned int)) 
ld.lld: error: undefined symbol: OH_Huks_BuildParamSet 
 
referenced by hello.cpp:16 (C:/my/harmonyos-project/hos1230/har1withso/src/main/cpp/hello.cpp:16) 
CMakeFiles/har1withso.dir/hello.cpp.o:(InitParamSet(OH_Huks_ParamSet**, OH_Huks_Param const*, unsigned int)) 
clang++: error: linker command failed with exit code 1 (use -v to see invocation) 
ninja: build stopped: subcommand failed. 
Detail: Please check the message from tools.

解决措施

在cmake文件里加一行target_link_libraries(hello_openharmony PUBLIC libhuks_ndk.z.so),然后把hello_openharmony换成自己的模块。