[CMake] linking: absolute path vs -l<libname>
Hendrik Sattler
post at hendrik-sattler.de
Wed Sep 2 06:11:24 EDT 2015
Hi,
is the netcdf find module defining an imported target? AFAIK, imported targets are always linked by full path. Else the rules already mentioned apply.
HS
Am 28. August 2015 10:23:47 MESZ, schrieb "Nico Schlömer" <nico.schloemer at gmail.com>:
>Hi everyone,
>
>I'm curious about when CMake decides to link a library by its absolute
>path
>and when it links using the `-l*` syntax. I came across this for the
>very
>simple test problem
>```
>cmake_minimum_required(VERSION 3.0)
>
>project(mytest)
>
>find_package(ZLIB REQUIRED)
>find_package(netCDF REQUIRED)
>
>add_executable(mytest main.cpp)
>target_link_libraries(
> mytest
> ${ZLIB_LIBRARIES}
> ${netCDF_LIBRARIES}
> )
>```
>The resulting link line is
>```
>/usr/bin/c++ CMakeFiles/mytest.dir/main.cpp.o -o mytest
>-rdynamic
>-lz /usr/lib/x86_64-linux-gnu/libnetcdf.so.7.3.0
>```
>so ZLIB is linked with `-lz`, netCDF with the full absolute path.
>
>Seems inconsistent? (ZLIB by the way is found through CMake's
>FindZLIB.cmake, netCDF by their own export files.)
>
>So far, I had been under the impression that `-l*` defeats the purpose
>of
>CMake a little bit as it asks the linker to search in the system's
>paths
>for a libz.so, something CMake has already done.
>
>A little clarification here would be great.
>
>Cheers,
>Nico
>
>
>------------------------------------------------------------------------
>
>--
>
>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/20150902/2a92e085/attachment.html>
More information about the CMake
mailing list