How to get CMake to link an executable to an external shared library that is not build within the same CMake project?
Just doing target_link_libraries(GLBall ${CMAKE_BINARY_DIR}/res/mylib.so) gives the error
target_link_libraries(GLBall ${CMAKE_BINARY_DIR}/res/mylib.so)
make[2]: *** No rule to make target `res/mylib.so', needed by `GLBall'. Stop. make[1]: *** [CMakeFiles/GLBall.dir/all] Error 2 make: *** [all] Error 2 (GLBall is the executable)
after I copied the library into the binary dir bin/res.
bin/res
I tried using find_library(RESULT mylib.so PATHS ${CMAKE_BINARY_DIR}/res)
find_library(RESULT mylib.so PATHS ${CMAKE_BINARY_DIR}/res)
Which fails with RESULT-NOTFOUND.
RESULT-NOTFOUND
Set libraries search path first:
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/res)
And then just do
TARGET_LINK_LIBRARIES(GLBall mylib)
2.1m questions
2.1m answers
60 comments
57.0k users