I'm working on a CMake project which builds a shared object, let's call it libfoo.so
which has to be dynamically linked to another shared object libbar.so
. This later one is not built from files contained in the project itself but rather just copied into the build directory from an external source during the invocation of cmake
. To make CMake aware of this file I've tried doing the following:
add_library(bar SHARED IMPORTED GLOBAL)
set_target_properties(bar PROPERTIES
IMPORTED_LOCATION some/path/to/libbar.so
)
And then to build libfoo.so
I do (in another CMakeLists.txt in an unrelated directory):
add_library(foo SHARED ...)
target_link_libraries(foo bar)
However, this does not work as desired, when running make VERBOSE=1
after cmake
the output shows that libfoo.so
is linked with -lbar
instead of libbar.so
.
If necessary I can try creating a minimal working example but maybe someone has encountered the same problem and can tell me what's going wrong.