Implicit conversion of full library path into `-lX` flag during linking: linker errors
Behavior occurs with both CMake 3.12 and 3.16 on Red Hat 7 with GCC 7.2.0.
I'm trying to understand some behavior of target_link_libraries
. I'm trying to build, e.g. the templight project with Boost. I am passing the full paths to libboost .so files to target_link_libraries
. However, when I link, the CMake command is not passing full paths but instead -l versions.
This implicit conversion is causing chaos because the default GCC linker paths are grabbing the wrong versions of the libraries (which live in /usr/lib64).
Some notes:
- This is all done in the same environment. I am not configuring in one environment and then rebuilding later in a different environment.
- The Boost libraries that I do want are in LD_LIBRARY_PATH
- If I remove Boost from my LD_LIBRARY_PATH and configure, CMake adds the full .so path to my link line. I no longer get -l flags instead.
- My GCC linker does not prioritize LD_LIBRARY_PATH over default paths (apparently)
I couldn't find any documentation on this and didn't know where to look in the source code.
Is there some scenario where CMake would change a full library path into a -l
flag instead?