Tor
Tor

Reputation: 785

CMake link behaviour depends on BOOST_ROOT

I'm using CMake to build a project which among other things link to boost. I use CMake 2.8.7, I have

set(Boost_NO_SYSTEM_PATHS true)

and I use

find_package(Boost COMPONENTS system filesystem regex REQUIRED)

I then link using

target_link_libraries(projectname ${Boost_LIBRARIES})

I use the environment variable BOOST_ROOT to specify the location of Boost, and my question is as follows:

When I set

BOOST_ROOT=/opt/Boost_1_47

CMake passes the full path to the libraries to the linker, whereas if I set

BOOST_ROOT=/usr

it links using

-lboost_filesystem-mt

etc. CMakeLists.txt is the same in both cases, the only thing I change is the environment varible BOOST_ROOT. Why doesn't CMake pass the full path in both cases?

Upvotes: 0

Views: 389

Answers (1)

bikram990
bikram990

Reputation: 1115

The linker is able to find the libraries which are in standard paths like /lib, /lib64, /usr/lib, /usr/lib64 etc. So in that case CMake does not feel the need to tell the linker where is the library is located. But in case of /opt/boost_1_47, as its not a standard path so linker doesn't know where is the library located.

Just try setting the LINK_DIRECTORIES in CMake to Path/To/Boost/Libraries you will notice a different behavior.

Upvotes: 1

Related Questions