[CMake] absolute library path, sorry for the question

Bo Zhou bo.schwarzstein at gmail.com
Wed Dec 13 05:12:00 EST 2017


Hi

CMAKE_SKIP_RPATH usually is used for the shared module which might want to
have the customized distributed path such as within the application.
According personal experience on POSIX systems (Linux, UNIX, OSX), always
enable CMAKE_SKIP_RPATH for the all local shared dependencies, and to the
final distribution, (if needed) put shared libraries into the lib folder of
distribution.

According your description, I'm not sure how did you pick up your library
into the application from CMake, usually we have to make sure the CMake
always chooses the libraries from 3rd-party directory not system or another
places. In our system, it has a variable THIRDPARTY_DIR for command
FIND_PATH() to locate the folder which contains the all built libraries,
then use HINTS and NAMES in the command FIND_PATH() and FIND_LIBRARY() to
locate the correct paths for the pre-built libraries, so the linking should
be okay.

If everything has no error, but just the application always picks up the
system's library not the 3rd-party libraries we prepared, one solution
would add another loader script for the application, from the loader script
it appends the local lib folder to LD_LIBRARY_PATH, then launch the actual
application executable file. A lot of commercial application on Linux solve
the similar issue by this way.

Wish my reply is helpful.

Thank you very much.

On Wed, Dec 13, 2017 at 6:06 PM, Mario Emmenlauer <mario at emmenlauer.de>
wrote:

>
> Dear cmake users,
>
> I have found good documentation on the cmake wiki about RPATH and
> its different variables, and also on the mailing lists. But somehow
> it still does not add up for me. Can you please help?
>
> I use cmake 3.9.5 on different platforms, CentOS 6 and Ubuntu 14.04
> amongst others. I build many standard libraries (like tiff and jpeg)
> into my own thirdparty directory, and set CMAKE_PREFIX_PATH to find
> them there. On newer Linux and Windows, cmake uses always the absolute
> path to those libraries, and everything works fine. But on older Linux
> like Ubuntu 14.04 and CentOS 6 it does not. cmake will first find the
> library in the correct absolute thirdparty directory, and I can confirm
> this by printing the 'XXX_LIBRARIES' variable in the find script. But
> later the Makefile will link with '-lxxx' instead of the full path.
> This makes 'ld' use the system library instead!
>
> I completely fail to understand at what point cmake changes XXX_LIBRARIES
> from an absolute path to '-lxxx', for example for libjpeg.
>
> I have experimented with CMAKE_SKIP_BUILD_RPATH, but it does not help.
> The only workaround I could find is to add the thirdparty directory to
> LDFLAGS. Then 'ld' will also find the correct library.
>
>
> Is this a bug, or an expected behavior? What parameters should I add
> when I invoke cmake so that it will always use libraries with their
> full path?
>
>
> Cheers,
>
>     Mario Emmenlauer
>
>
>
> PS: since I build thirdparty libraries, I prefer not to change their
> CMakeLists.txt but would rather prefer to set better cmake command line
> parameters.
>
>
> References:
> https://cmake.org/Wiki/CMake_RPATH_handling
> https://cmake.org/pipermail/cmake/2015-September/061462.html
>
>
>
> --
> BioDataAnalysis GmbH, Mario Emmenlauer      Tel. Buero: +49-89-74677203
> Balanstr. 43                   mailto: memmenlauer * biodataanalysis.de
> D-81669 München                          http://www.biodataanalysis.de/
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171213/150473bc/attachment.html>


More information about the CMake mailing list