I'm trying to have CMake 2.8.6 link to boost::program_options using the following code in my CMakeLists.txt
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR})
ADD_EXECUTABLE (segment segment.cpp)
TARGET_LINK_LIBRARIES (segment ${Boost_LIBRARIES})
The find command seems to succeed but passes the wrong directory to the linker. The package is actually in:
`/usr/lib64/libboost_program_options-mt.so.5`
but CMakeFiles/segment.dir/link.txt
lists the following:
/cm/shared/apps/gcc/4.4.6/bin/c++ CMakeFiles/segment.dir/segment.cpp.o -o segment -rdynamic /usr/lib64/lib64/libboost_program_options-mt.so.5 -lpthread -lrt -Wl,-rpath,/usr/lib64/lib64
Note the extra lib64
in the path. Also, the -l flag in front of the path seems to be missing.
When running CMake it reports that it correctly finds the package, and the {$Boost_LIBRARIES}
variable seems to list the correct libs:
Boost found.
Found Boost components:
program_options
${Boost_LIBRARIES} - optimized;boost_program_options-mt-shared;debug;boost_program_options-mt-shared-debug
The generated CMakeCache.txt file starts with:
//The directory containing a CMake configuration file for Boost.
Boost_DIR:PATH=/usr/lib64/boost
//Boost include directory
Boost_INCLUDE_DIR:FILEPATH=/usr/include
Which seems to be correct. But when running make it uses the path in link.txt above and I get the error:
make[2]: *** No rule to make target `/usr/lib64/lib64/libboost_program_options-mt.so.5', needed by `segment'. Stop.
make[1]: *** [CMakeFiles/segment.dir/all] Error 2
make: *** [all] Error 2
What might cause this extra injection of a subdir into the path? What might cause link.txt to be generated in this way? And how do I fix it (or work around it)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…