如何在Cmake for Android中导入共享库 [英] How to import shared libraries in Cmake for Android

查看:93
本文介绍了如何在Cmake for Android中导入共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图使用CMake导入Android项目,但是当我尝试导入这些库并使用终端在Andorid上编译并执行程序时,出现以下错误:

I have been trying to import a project for Android using CMake but when I try to import these libraries and compile and execute the program on Andorid using terminal, I get the following error:

D/AndroidRuntime( 6162): Shutting down VM
E/AndroidRuntime( 6162): FATAL EXCEPTION: main
E/AndroidRuntime( 6162): Process: org.abc.project, PID: 6162
E/AndroidRuntime( 6162): **java.lang.UnsatisfiedLinkError: dlopen failed: library "libcsoundandroid.so" not found**
E/AndroidRuntime( 6162):    at java.lang.Runtime.loadLibrary(Runtime.java:371)
E/AndroidRuntime( 6162):    at java.lang.System.loadLibrary(System.java:988)
E/AndroidRuntime( 6162):    at org.qtproject.qt5.android.bindings.QtActivity.loadApp

我的 CMakeLists.txt 是:

add_library(csoundandroid SHARED IMPORTED)
set_property(TARGET csoundandroid PROPERTY IMPORTED_LOCATION /home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi/)

add_library(sndfile SHARED IMPORTED)
set_property(TARGET sndfile PROPERTY IMPORTED_LOCATION /home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi/)

add_library(c++_shared SHARED IMPORTED)
set_property(TARGET c++_shared PROPERTY IMPORTED_LOCATION /home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi/)
set(LIBS1 libcsoundandroid.so)
set(LIBS2 libsndfile.so)
set(LIBS3 libc++_shared.so)
link_directories(/home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi)

include_directories(/home/ayush/csound/include)
include_directories(/home/ayush/csound/android/CsoundAndroid/jni/)
target_link_libraries(abc ${LIBS1} ${LIBS2} ${LIBS3} )

此处 abc 是生成的可执行文件.我在那里列出的所有图书馆都在同一地方.您能帮我找出错误所在吗?任何帮助将不胜感激.

Here abc is the executable file generated. All my libraries listed there are at the same place. Could you help me find out what the error is? Any kind of help would be highly appreciated.

推荐答案

属性 IMPORTED_LOCATION 应该包含库文件的完整路径.该属性明确地写在文档中.

Property IMPORTED_LOCATION should contain full path to the library file. This is explicitely written in documentation for that property.

要与导入的库链接,请使用目标名称,而不是库文件:

For link with imported library, use target name, not a library file:

# Correctly set property for imported library
set_property(TARGET csoundandroid PROPERTY IMPORTED_LOCATION
    /home/ayush/csound-android-6.07.0/(...)/armeabi/libcsoundandroid.so
)

# And correctly link with it
set(LIBS1 csoundandroid)

target_link_libraries(abc ${LIBS1})

这篇关于如何在Cmake for Android中导入共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆