I am trying to include a dynamic library in my project and I am setting up the compilation using the following CMake script:
find_package( DLIB 18.18.0 REQUIRED )
include_directories( ${DLIB_INCLUDE_DIRS} )
add_executable( executable executable.cxx )
target_link_libraries( executable ${dlib_LIBRARIES} )
If I print the directories of the variable ${dlib_LIBRARIES} I get:
/Users/../INSTALL/lib/libdlib.dylib
Which is correct and compiles. The problem comes when executing the executable and gives the following runtime error:
dyld: Library not loaded: libdlib.18.18.0.dylib
Referenced from: /Users/.../bin/executable
Reason: image not found
Trace/BPT trap: 5
And this seem logic because if I run otool -L executable I get a relative path instead of an absolute path:
$otool -L executable
libdlib.18.18.0.dylib (compatibility version 0.0.0, current version 18.18.0)
Why the path shown by otool is not the same as the path added with target_link_libraries and how could I solve this issue with cmake?