简体   繁体   中英

How to link prebuilt .so files using CMakeLists.txt

I am trying to use cmake with android studio to compile c++ code, and I have a .so library which needs to be linked with the target.

I am new to cmake and this is what I have:

add_library(
    my_target
    SHARED
    ${SRCS}
)

find_library(
    SSL
    apex_fips_libs/libccmssl.so
)

target_link_libraries(
    my_target
    ${SSL}
)

Folder structure:

-- Src
   -- some.cpp
   -- some2.cpp
   -- CMakeLists.txt
   -- apex_fips_libs
       --libccmssl.so

But I am getting following error:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
  SSL

I understand that SSL is not being set as find_library does not find the .so , but why?

I even tried using the absolute path. Can someone point me to the correct way of doing this?

Thank You.

If you're guaranteed to have that library there already built then perhaps this is the easiest solution

target_link_libraries(my_target ${CMAKE_SOURCE_DIR}/apex_fips_libs/libccmssl.so)

Otherwise you might want to try something more like

find_library(SSL NAMES ccmssl PATHS ${CMAKE_SOURCE_DIR}/apex_fips_libs)
target_link_libraries(my_target ${SSL})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM