0

Recently, I'v been developing a native c++ project with Android studio, which needs some other external open source libraries. I want to involve these libraries (for example, hello library)inside the Android Studio project by using CMake's add_subdirectory command to ease my code management. I refer the online guide doc from https://developer.android.com/studio/projects/configure-cmake, but not completely. Concretly, I add the following items to my top level CMakeList.txt:

set( lib_src_DIR /Users/dependencies/hello-1.1.1 ) set( lib_build_DIR /Users/dependencies/hello ) file(MAKE_DIRECTORY ${lib_build_DIR}) add_subdirectory( ${lib_src_DIR} ${lib_build_DIR} ) 

the whole top level CMakeLists.txt post as the following picture: top level CMakeLists.txt

Everything's done, I build this project, what I expect to see is libhello.a in the /Users/dependencies/hello directory, but there's only some Cmake related files, like following: enter image description here

Thers's no libhello.a found in the hello directory and its subdirectories, it seems like my hello library is not compiled at all. The following picture is my hello project's CMakeList.txt: enter image description here I'm sure this hello project can compile because I tried use cmake command to compile it directly, it's ok.

So, why add_subdirectory in the top level CMakeLists.txt don't work? Was I missing some other settings ? By the way, this top level CMakeLists.txt was genereated by the Android Studio automatically when I create the native C++ project, I just add something in it.

4
  • do these external dependency libraries have to be compiled individually ? Commented Nov 3, 2021 at 3:36
  • Stack Overflow discourages using images with the text (code, error message, etc.). Please, replace images of code with the itself. See also How to Ask. Commented Nov 3, 2021 at 6:52
  • Where do actually use (link against) the hello static library? Commented Nov 4, 2021 at 12:28
  • well, it's not the key point. hello is just for my test, I didn't link against it yet. But even this , it still suppose to be generated. But with STATIC, it's not compiled. While using SHARED, it's can generate libhello.so . There's a post discussing about this problem long ago, I found it on the website and convice myself it's the Android Studio's problem. Commented Nov 5, 2021 at 4:04

1 Answer 1

0

Okay, it turns out that's the Android Studio's bug, it only can generate synamic libraries(.so), if you specify the library as static, it won't compile.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.