0

Using conan and CMake 3.6, I have a conanfile.txt like this:

[requires]
boost/1.73.0@myProject-3rd-party-dependencies/rhel7
xerces-c/3.2.3@myProject-3rd-party-dependencies/rhel7

[generators]
cmake
cmake_find_package
virtualenv
virtualrunenv

This generates Findboost.cmake and Findxerces-c.cmake files. My CMakeLists.txt contains the line: link_libraries(boost::boost xerces-c::xerces-c)

When the makefile generated by cmake links my target the link command looks like this:

/usr/local/bin/g++     -g        CMakeFiles/xsd-packager.dir/xsd-packager/src/main/c++/Main.cpp.o
-o xsd-packager
-L/home/lindbjs1/.conan/data/boost/1.73.0/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib
-L/home/lindbjs1/.conan/data/xerces-c/3.2.3/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib
-Wl,-rpath,/home/lindbjs1/.conan/data/boost/1.73.0/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib:/home/lindbjs1/.conan/data/xerces-c/3.2.3/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib:::::::::::::::::::::::::::::::::::::::::::::::::
/home/lindbjs1/.conan/data/boost/1.73.0/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib/libboost_system.so
… and so on for the other boost libraries…
/home/lindbjs1/.conan/data/xerces-c/3.2.3/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib/libxerces-c.so
/home/lindbjs1/.conan/data/xerces-c/3.2.3/myProject-3rd-party-dependencies/rhel7/package/87fb0b451a964f931487412a0e21bdef04c50390/lib/libxerces-c-3.2.so 

The behavior is the same if I use target_link_libraries for the individual targets instead of the global link_libraries. The -L options are correct. (I haven't looked into why the -Wl,-rpath option ends with a multitude of colons.) How do I, or can I, get cmake to use, e.g., -lboost_system, instead of the full pathnames to the imported libraries?

  • P.S. The target for the executable shown above is `add_executable(xsd-packager xsd-packager/src/main/c++/Main.cpp)` – Jon Lindberg Jul 02 '20 at 15:17
  • It seems the use of the full-path to the libraries in your linker commands is redundant. The full path to each of the Boost files, for example, is encapsulated in the encompassing CMake target `boost::boost`. Unless you want to manually edit the `Findboost.cmake` module file, it's probably best to leave this alone. However, perhaps you *can* remove the capital `-L` linker commands. If your CMake file contains a `link_directories()` command, you can try removing it (you didn't provide your CMake file so going off of conjecture here...). – Kevin Jul 02 '20 at 19:04
  • There is a link_directories buried in the generated conanbuildinfo.cmake. Presumably that causes the -L options, as @squareskittles says, but I want to keep those and remove the full path library files. – Jon Lindberg Jul 02 '20 at 21:15

0 Answers0