Reza
Reza

Reputation: 360

Including my own shared library with cmake

I have the following code in my CMakeLists.txt for finding my shared library libsieve.so

set(CPPLIB_DIR "${CMAKE_SOURCE_DIR}/../core/build")
find_library(CPPLIB_SIEVE_LIBRARY NAMES libsieve PATHS CPPLIB_DIR)

But it fails and won't find my library. I have the following directory structure:

What am I doing wrong?

Upvotes: 0

Views: 477

Answers (2)

Dmitry
Dmitry

Reputation: 3143

I don't know why cmake doesn't find the needed library but I can suggest a way to make it happen with the help cmake-gui: if the first run of "configure" fails to find the library you can point it to the needed library manually (set the full absolute path). Most of the time such solution works for me.

Also if the library was built with one tool chain (say, Intel C++) and you project is being built with another tool chain (say, clang) the failure to find the library may be due to binary incompatibility between the project and the library.

Upd. The original problem was referencing CPPLIB_DIR. It should have been:

find_library(CPPLIB_SIEVE_LIBRARY NAMES sieve PATHS ${CPPLIB_DIR})

Upvotes: 1

Michael Mera
Michael Mera

Reputation: 108

Cmake find_library expect you to provide the library name or the library file name.

You mixed the two by adding a "lib" prefix to your library name. So you should try to replace libsieve by either sieve or libsieve.so.

Upvotes: 0

Related Questions