Native so 编译 opencv,报找不到 libunwind.so
下载 opencv 3.4.2 版本,使用鸿蒙编译工具链编译出 libopencv.so, 作为底层库链接。在 Native C++ 模版工程,添加一个getversion()方法,同时 cmakelists 文件链接 opencv 库(include同样也配好)。
添加预构建共享库
add_library(opencv SHARED IMPORTED)
设置预构建共享库的路径
set_target_properties(opencv PROPERTIES IMPORTED_LOCATION <math><semantics><mrow><mrow><mi>N</mi><mi>A</mi><mi>T</mi><mi>I</mi><mi>V</mi><mi>E</mi><mi>R</mi><mi>E</mi><mi>N</mi><mi>D</mi><mi>E</mi><msub><mi>R</mi><mi>R</mi></msub><mi>O</mi><mi>O</mi><msub><mi>T</mi><mi>P</mi></msub><mi>A</mi><mi>T</mi><mi>H</mi></mrow><mi mathvariant="normal">/</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>b</mi><mi>u</mi><mi>i</mi><mi>l</mi><msub><mi>t</mi><mi>l</mi></msub><mi>i</mi><mi>b</mi><mi>s</mi><mi mathvariant="normal">/</mi></mrow><annotation encoding="application/x-tex">{NATIVERENDER_ROOT_PATH}/prebuilt_libs/</annotation></semantics></math>NATIVERENDERROOTPATH/prebuiltlibs/{OHOS_ABI}/libopencv.so)
将预构建共享库链接到目标
target_link_libraries(${PROJECT_NAME_AD} PUBLIC opencv)
问题场景描述:点击crash: Cannot read property getVersion of undefined加载:log 搜 dlopen,有如下报错01-12 16:36:49.725 13173-13173 C03F00/MUSL-LDSO pid-13173 E dlopen_impl load library header failed for libunwind.so01-12 16:36:49.728 13173-13173 C039FE/NAPI pid-13173 W [(native_module_manager.cpp:745)(LoadModuleLibrary)] dlopen failed: Error loading shared library : Invalid argument (needed by /data/storage/el1/bundle/libs/arm64/libopencv.so)
如何解决呢?
在主体工程cmakelist中通过add_subdirectory构建中间层,在中间层中单独依赖三方库