0

Im trying to build android application with Qt creator and I need to link pjsip libraries.

I builded pjsip for android and made a "sudo make install"

Then I link the libraries in CMakeLists.txt file with pkg-config like this:

find_package(PkgConfig REQUIRED)
pkg_check_modules(PJSIP REQUIRED libpjproject)

target_link_libraries(tid_trains_android PUBLIC ${PJSIP_LIBRARIES})
target_include_directories(tid_trains_android PUBLIC ${PJSIP_INCLUDE_DIRS})
target_compile_options(tid_trains_android PUBLIC ${PJSIP_CFLAGS_OTHER})

The libs are in /usr/local/bin but It cannot find them. Gives me errors:

error: cannot find -lpjsua2-armv7-unknown-linux-android
error: cannot find -lpjsua-armv7-unknown-linux-android
error: cannot find -lpjsip-simple-armv7-unknown-linux-android
...

Do I need to put the libraries somewhere else? In the ndk directory somewhere?

acho
  • 11
  • 4
  • If you have relatively new CMake, then it is simpler (and better) to use `IMPORTED_TARGET` option for `pkg_check_modules`, like described in [this answer](https://stackoverflow.com/a/57224542/3440745) to the duplicate question. If you don't want to use imported target, then your current approach lacks for call to `target_link_directories` or `link_directories` with `PJSIP_LIBRARY_DIRS` variable. While these calls are not specified in the [most voted answer](https://stackoverflow.com/a/29316084/3440745), the comments note about them. – Tsyvarev Mar 01 '22 at 22:42
  • It didn't worked with IMPORTED_TARGET, however I resolved the issue by building the library with different prefix=/home/mmc/pjsip and then: `set(ENV{PKG_CONFIG_PATH} "/home/mmc/pjsip/lib/pkgconfig")` It seems that cmake doesnt understand the `-L/home/mmc/pjsip/lib` from the pkg-config because it didn't work without `target_link_directories(untitled3 PUBLIC "/home/mmc/pjsip/lib")` I have I question: Do cmake get the CXX_FLAGS from the pkg-config with only the line: `target_link_libraries(untitled3 PUBLIC PkgConfig::PJSIP)`? – acho Mar 02 '22 at 18:52
  • Compiler flags are automatically propagated when use IMPORTED_TARGET. – Tsyvarev Mar 02 '22 at 19:04
  • As for link directories, current CMake provides a variable with suffix `_LINK_LIBRARIES`, which contains **absolute paths** to the libraries. CMake tries to determine these paths according to `-L` options: https://github.com/Kitware/CMake/blob/master/Modules/FindPkgConfig.cmake#L283. So, if your `.pc` file is correct, then you could use variable `PJSIP_LINK_LIBRARIES` instead of `PJSIP_LIBRARIES` one and don't bother about `link_directories`. – Tsyvarev Mar 02 '22 at 19:12

0 Answers0