问题
问题如下

libWtCore.a(CtaStrategyMgr.cpp.o): in function `boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&, boost::filesystem::directory_options)':
undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, unsigned int, boost::system::error_code*)'
可能的问题原因以及尝试过的方法
1.未正确链接 Boost.Filesystem 和 Boost.System 库
在cmake文件中链接Boost.Filesystem 和 Boost.System
find_package(Boost REQUIRED COMPONENTS filesystem system)
target_link_libraries(WtRunner Boost::filesystem Boost::system)
2.WtCore库可能未正确链接boost
在构建WtCore的Cmake文件中添加这一行
TARGET_LINK_LIBRARIES(WtRunner boost_filesystem boost_system)
最终解决方法
Cmake文件内容如下
INCLUDE_DIRECTORIES(${INCS})
LINK_DIRECTORIES(${LNKS})
LINK_DIRECTORIES(../WtCore/cmake-build-debug/build_/Debug/libs
../WTSTools/cmake-build-debug/build_/Debug/libs
../WTSUtils/cmake-build-debug/build_/Debug/libs
)
SET(LIBS
WtCore
WTSTools
WTSUtils
)
IF (MSVC)
LIST(APPEND LIBS ws2_32)
ELSE(GNUCC)
LIST(APPEND LIBS
dl
pthread
boost_filesystem
boost_thread)
IF(WIN32)
LIST(APPEND LIBS
ws2_32 iconv)
ENDIF()
ENDIF()
ADD_EXECUTABLE(WtRunner ${SRCS} ${HDRS})
TARGET_LINK_LIBRARIES(WtRunner ${LIBS})
注意看这两行,这两个变量并没有被定义过,他们本应该在上一级的Cmake文件中被定义,而我只是为了独立编译一个小模块,所以实际上这两行代码是不生效的。
INCLUDE_DIRECTORIES(${INCS})
LINK_DIRECTORIES(${LNKS})
由于我的linux系统中存在多个boost版本,因此推测编译时使用的boost和链接时的boost并不是一个版本,因此加上下面两行:(保证编译和链接一致)
# 设置编译时的boost头文件的路径
include_directories(/usr/local/include/boost)
# 设置链接时的boost库的路径
link_directories(/usr/local/lib)
1317

被折叠的 条评论
为什么被折叠?



