0

I am building a native C++ android project. I want to use a given shared library (general). folder structure

The .so files are in their respective folder, and the headers are in the include/general folder. My cmake file looks like this:

add_library(general SHARED IMPORTED)

set_target_properties(general PROPERTIES
        IMPORTED_LOCATION  "${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libgeneral.so"
        )

include_directories(include/general)

...

target_link_libraries( # Specifies the target library.
        hello_cmale
        general
        ${log-lib}
        )

SOLVED: general is a keyword. Just rename the library in the cmake file to general_lib.

  • 1
    Please, add the **exact error message** to the question post (this message should include which symbol is undefined, which source file is compiled and so on). Then check that your `.so` file **actually defines** that symbol: https://stackoverflow.com/questions/34732/how-do-i-list-the-symbols-in-a-so-file, and add result of the check to the question post too. – Tsyvarev Jul 31 '23 at 09:43
  • Post updated, the .so file defines all the symbols. –  Jul 31 '23 at 10:05
  • I see no `libgeneral.so` file in the linker command line. Are you sure that you build exactly that project which you show us? – Tsyvarev Jul 31 '23 at 10:18
  • I also noticed this, but I don't know why. To build I use android studio, so I can see the CMake `message("..") ` output. So I suppose that I build this project. Also, I cleaned and rebuilded the project. –  Jul 31 '23 at 10:22
  • Still, according to the command line it smells like CMake doesn't process the code which you show us. It processes **very similar** code: `hello_cmale` as the target name, linking with `log` library... but linkage with `general` is not processed. I would suggest you to debug in that direction. I fear only you may perform such debugging. My last guess is that `target_link_libraries` call is conditional, and that condition is not performed during the actual configuration. You said that you tried to insert `message` calls, but have you tried to insert that call near the `target_link_libraries`? – Tsyvarev Jul 31 '23 at 10:35
  • Adding the .so path to the target link directories command afether the library name seems to work. –  Jul 31 '23 at 10:41
  • Wait, .so on Windows? – Something Something Jul 31 '23 at 15:36
  • Yes. While building the android app on android studio I must add the .so files to the project no? –  Aug 01 '23 at 14:08

0 Answers0