Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 链接boost程序选项时未解析的符号_C++_Cmake_Boost Program Options - Fatal编程技术网

C++ 链接boost程序选项时未解析的符号

C++ 链接boost程序选项时未解析的符号,c++,cmake,boost-program-options,C++,Cmake,Boost Program Options,我的项目的用户向我报告了此错误。我不能在我的计算机或实验室的服务器上复制它,所以我在这里问它 该项目使用CMake生成构建环境。它使用FindBoost实用程序(由CMake提供)查找Boost资源 一开始,我的用户在链接最终程序时说,编译器提供了“/usr/lib64/lib64/libboost_XXX.so”,而不是正确的“/usr/lib64/libboost_XXX.so”。我没有找到为什么CMake生成了如此奇怪的库位置,并要求他手动设置变量Boost_库,然后打印它们: Boost

我的项目的用户向我报告了此错误。我不能在我的计算机或实验室的服务器上复制它,所以我在这里问它

该项目使用CMake生成构建环境。它使用FindBoost实用程序(由CMake提供)查找Boost资源

一开始,我的用户在链接最终程序时说,编译器提供了“/usr/lib64/lib64/libboost_XXX.so”,而不是正确的“/usr/lib64/libboost_XXX.so”。我没有找到为什么CMake生成了如此奇怪的库位置,并要求他手动设置变量Boost_库,然后打印它们:

Boost libraries are: /usr/lib64/libboost_thread-mt.so;/usr/lib64/libboost_program_options-mt.so;/usr/lib64/libboost_filesystem-mt.so
事情似乎是对的。汇编工作取得了成功。但在连接时,程序会对许多未定义的符号哭诉:

CMakeFiles/ht-filter.dir/ht-filter.cpp.o: In function `parse_options(int, char**)':
/public/home/yli/Downloads/htqc-0.15.0-Source/ht-filter.cpp:43: undefined reference to `boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
......
/usr/local/include/boost/program_options/errors.hpp:372: undefined reference to `boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)'

我用户的操作系统是CentOS 6.2,他的Boost版本是1.50.0,与我电脑中的版本相似。我的用户的CMake版本是2.8.11,与我的版本相同。

使用CMake的find_包进行Boost时,您可以给CMake一些提示,帮助它找到正确的库,例如:

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

set(BOOST_ROOT "/usr")

find_package(Boost 1.50.0)

message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
另外,如果您正在链接动态libs,请确保让Boost头知道这一点(我认为您不应该弄乱这里的顺序):


可能您的用户安装了2个版本的boost,或者1个版本和另一个版本的一些“剩余”版本?
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

set(BOOST_ROOT "/usr")

find_package(Boost 1.50.0)

message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
link_directories(${Boost_LIBRARY_DIRS})

include_directories(${Boost_INCLUDE_DIRS})

add_definitions( -DBOOST_ALL_DYN_LINK )