[CMake] Absolute Path linking library
Laurent Chauvin
lchauvin at bwh.harvard.edu
Tue Sep 3 21:47:45 EDT 2013
Hello everyone,
I'm working on a library, and I would like the users be able to create their own program and liking to my library (by specifying path in cmake).
I created the library and an example to test it.
Everything compiles.
However, when I try to run my example I have this error:
MyExample:
libMyLib.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
The problem is my example is not in the same directory as my library (not even in a subdirectory).
And it seems it's linking to my library with a relative path.
If I add the path of my library in DYLD_LIBRARY_PATH it works, but I would like the users to be able to compile and link straight forward.
To link the library to my example I use find_package(MyLib REQUIRED) and include(${MyLib_USE_FILE}) which basically do a LINK_DIRECTORIES with the absolute path of the library.
Then I do add_executable and target_link_libraries(MyExample ${MyLib_LIBRARIES})
Compilation is working fine. There is these options:
-L/Absolute/Path/To/MyLib -lMyLib
But at runtime, library cannot be found.
Would it be possible to put the full path of my library when linking in the CMakeLists ?
Thank you.
-Laurent
More information about the CMake
mailing list