关于android studio。当我编辑 JNI 以使用 c/c++ 代码时,但 c/c++ 代码使用另一个 lib .a,所以我如何编辑我的 CMakeList.txt,请帮助我,如果你擅长使用 Android Studio enter image description here
这是我的 CMakeList.txt 当我做项目时。它说“/../../mips64el-linux-android/bin\ld: 找不到-lwebsockets”
cmake_minimum_required(VERSION 3.4.1)
aux_source_directory(src/main/cpp/android_src/common FILE_COMMON)
aux_source_directory(src/main/cpp/android_src FILE_SRC)
aux_source_directory(src/main/cpp/ FILE_CPP)
SET(ALL_FILE ${FILE_CPP} ${FILE_SRC} ${FILE_CPP})
INCLUDE_DIRECTORIES(src/main/cpp/cpp_include)
#LINK_DIRECTORIES(src/main/cpp/cpp_lib)
add_library( websockets STATIC IMPORTED)
set_target_properties(websockets PROPERTIES IMPORTED_LOCATION src/main/cpp/cpp_lib/libwebsockets.a)
add_library( # Sets the name of the library.
#native-lib
SkylightWebSocket
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
#src/main/cpp/native-lib.cpp
${ALL_FILE})
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
#native-lib
SkylightWebSocket
# Links the target library to the log library
# included in the NDK.
libwebsockets.a ${log-lib})
最佳答案
在 target_link_libraries()
语句中使用 websockets 而不是 libwebsockets.a。
为了更容易理解,这里是一个编辑过的脚本:
add_library( Q STATIC IMPORTED)
set_target_properties(Q PROPERTIES IMPORTED_LOCATION src/main/cpp/cpp_lib/libwebsockets.a)
add_library( # Sets the name of the library.
#native-lib
SkylightWebSocket
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
#src/main/cpp/native-lib.cpp
${ALL_FILE})
target_link_libraries( # Specifies the target library.
#native-lib
SkylightWebSocket
# Links the target library to the log library
# included in the NDK.
Q log)
请注意,使用 NDK,定义了 log 库,您根本不需要 find_library
。
关于java - android studio 使用JNI 构建c/c++,但c/c++ 需要另一个lib.a,如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47573145/