我正在尝试使用我的CMakeLists.txt中的以下代码将CMake 2.8.6链接到boost :: program_options
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR})
ADD_EXECUTABLE (segment segment.cpp)
TARGET_LINK_LIBRARIES (segment ${Boost_LIBRARIES})
Run Code Online (Sandbox Code Playgroud)
find命令似乎成功但将错误的目录传递给链接器.该包实际上是:
`/usr/lib64/libboost_program_options-mt.so.5`
Run Code Online (Sandbox Code Playgroud)
但CMakeFiles/segment.dir/link.txt列出以下内容:
/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
Run Code Online (Sandbox Code Playgroud)
注意lib64路径中的额外内容.此外,路径前面的-l标志似乎缺失.
运行CMake时,它报告它正确找到包,并且该{$Boost_LIBRARIES}变量似乎列出了正确的库:
Boost found.
Found Boost components:
program_options
${Boost_LIBRARIES} - optimized;boost_program_options-mt-shared;debug;boost_program_options-mt-shared-debug
Run Code Online (Sandbox Code Playgroud)
生成的CMakeCache.txt文件以:
//The directory containing a CMake configuration file for Boost.
Boost_DIR:PATH=/usr/lib64/boost
//Boost include directory
Boost_INCLUDE_DIR:FILEPATH=/usr/include
Run Code Online (Sandbox Code Playgroud)
这似乎是正确的.但是当运行make时它使用上面link.txt中的路径,我得到错误:
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
Run Code Online (Sandbox Code Playgroud)
什么可能导致这个额外注入一个子目录进入路径?什么可能导致以这种方式生成link.txt?我该如何修复它(或解决它)?
小智 7
问题出在boost-devel分布式文件中:/usr/lib64/boost/Boost-relwithdebinfo.cmake
cmake-2.6软件包根本不使用此文件,因为FindBoost.cmake文件返回(正确)完整路径来增强库.cmake28-2.8.8 FindBoost.cmake文件返回类似"boost_date_time-mt-shared"的库字符串,这些字符串是/usr/lib64/boost/Boost-relwithdebinfo.cmake中定义的目标.
在/usr/lib64/boost/Boost-relwithdebinfo.cmake的最顶部,一个名为_IMPORT_PREFIX的变量是从cmake文件本身的位置定义的,然后像这样使用:
#----------------------------------------------------------------
# Generated CMake target import file for configuration "RelWithDebInfo".
#----------------------------------------------------------------
# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)
# Compute the installation prefix relative to this file.
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
# Import target "boost_date_time-static" for configuration "RelWithDebInfo"
SET_PROPERTY(TARGET boost_date_time-static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
SET_TARGET_PROPERTIES(boost_date_time-static PROPERTIES
IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libboost_date_time.a"
)
Run Code Online (Sandbox Code Playgroud)
这将_IMPORT_PREFIX设置为"/ usr/lib64",它与另一个在其中包含/ lib64 /的字符串连接.我发现如果我只是将文件更改为包含第三个GET_FILENAME_COMPONENT调用,它就可以正常工作.像这样:
#----------------------------------------------------------------
# Generated CMake target import file for configuration "RelWithDebInfo".
#----------------------------------------------------------------
# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)
# Compute the installation prefix relative to this file.
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
# Import target "boost_date_time-static" for configuration "RelWithDebInfo"
SET_PROPERTY(TARGET boost_date_time-static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
SET_TARGET_PROPERTIES(boost_date_time-static PROPERTIES
IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libboost_date_time.a"
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9631 次 |
| 最近记录: |