Issue
I generate the static library from another Android project, so pretty sure they're useable.
I got four .a files based on CPU architectures, one .h file which also has been tested.
Now in new project, another .c file want to call the static library, i can't combine the two projects, the static libraries must be called in .a format.
I got "CMake Error: CMake can not determine linker language for target", this is my CMakeLists.txt:
add_library(
mylib
STATIC
src/main/jniLibs/arm64-v8a/libmylib.a
src/main/jniLibs/armeabi-v7a/libmylib.a
src/main/jniLibs/x86/libmylib.a
src/main/jniLibs/x86_64/libmylib.a
)
target_link_libraries(
native-lib
mylib
)
mylib is the prebuilt library. native-lib want to call mylib.
A link about how to add .a file to a project from scrath is also welcome.
Solution
add_library(
my_static_lib
STATIC
IMPORTED
)
set_target_properties(features PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libmy_static_lib.a)
As you can see, i put those .a
files in
projectNmae\app\src\main\jniLibs\${ANDROID_ABI}\
,
if you change the location, remember to declare it in the CMakeList.txt
.
I put my_static_lib.h
in src\main\include
, and use it in other .c/cpp
file like:
#include "../include/features.h"
My BIGGEST mistake is the missed:
${CMAKE_SOURCE_DIR}
CMake cannot find STATIC library in locations like src/main/app/native-lib.c
, SHARED library is OK, not STATIC library, which is very strange.
And IMPORTED is a must, i tried replace it with the whole location path, won't work.
Thank you all the comments and answers, i hope this answer can help newbies like me.
Answered By - outcast
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.