BOOST_ROOT在链接阶段的cmake配置后不尊重

问题描述 投票:1回答:2

道歉冗长的标题。

我奋力由于cmake目录boost库的链接存在与/usr/lib64提升。我升压是在不同的地方编译,我指着cmakeBOOST_ROOT。意识到潜在的问题,我设定一个最小的版本和Boost_NO_SYSTEM_PATH。配置阶段工​​作正常,但连接的时候我得到一个错误:

test.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0xa8): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
 >, std::allocator<std::__cxx11::basic_string<char,std::char_traits<char>, std::allocator<char> > > > const&)'

这显然是捡了错误的库中的一个问题,我可以用make VERBOSE=2看到g++行不尊重BOOST_ROOT我以前发现的提升设置

g++ CMakeFiles/test.dir/test.cpp.o -o test -rdynamic -lboost_program_options-mt

但我希望这些方针的东西:

g++ ... -L/path/to/my/own/boost/lib -lboost_program_options-mt

作为“调试”的步骤我在cmake Boost_LIBRARY_DIRS打印出来的消息,我可以看到/path/to/my/own/boost/lib。当我“手动”添加-L标志链接的作品,这是我如何知道系统库仍在干扰。另外,我的*LIBRARY_PATH只在/path/to/my/own/boost/lib指向。

也许,这不是不可能的,这是FindBoost模块的错误,但我发现很难相信。这在我看来,还是有东西在cmake的主要我不明白?为什么没有在这种情况下或者特定文件的链接产生的-L标志?请指教。

这里是我的CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

set(Boost_NO_SYSTEM_PATHS ON)
find_package(Boost 1.67.0 REQUIRED COMPONENTS program_options)

include_directories(${Boost_INCLUDE_DIR})

add_executable(test test.cpp)

target_link_libraries(test LINK_PUBLIC ${Boost_PROGRAM_OPTIONS_LIBRARY})

而且我的程序:

#include <iostream>
#include <string>

#include <boost/program_options.hpp>

namespace po=boost::program_options;

int main( int argc, char* argv[]) 
{ 
    po::options_description options_description;
    po::positional_options_description positional_options_description;
    po::variables_map variables_map;


    options_description.add_options()
    ("help,h", "print usage message");
    po::store(po::command_line_parser(argc, argv).options(
        options_description).positional(positional_options_description).run(),
        variables_map);

    return 0; 
} 

Other relevant output

我使用qazxsw POI message后拔出从qazxsw POI配置步变量:

cmake
c++ boost cmake
2个回答
0
投票

我不知道你使用的是哪个版本的CMake但您尝试使用,而不是老式的CMake助力可变进口目标:

即替换:通过find_package ${Boost_INCLUDE_DIR} /path/to/my/own/boost/include ${Boost_LIBRARY_DIRS} /path/to/my/own/boost/lib ${Boost_LIBRARIES} /path/to/my/own/boost/lib/libboost_program_options-mt.so ${Boost_PROGRAM_OPTIONS_LIBRARY} /path/to/my/own/boost/lib/libboost_program_options-mt.so


0
投票

调用target_link_libraries(test LINK_PUBLIC ${Boost_PROGRAM_OPTIONS_LIBRARY})邮件列表,最后留下一个职位上target_link_libraries(test LINK_PUBLIC Boost::program_options)后,我意识到这个问题是没有这么多我的CMake的版本,而是我cmake-developer这是我从一个旧的项目继承。

我设置:

cmake gitlab issues

它更新到3.12,我得到了正确的行为后:

cmake_minimum_required

阅读cmake_minium_required(VERSION 2.8) 文档我了解,“命令隐式调用” /path/to/g++ -rdynamic CMakeFiles/test.dir/test.cpp.o -o test -lboost_program_options-mt 。我相信后者不会cmake_minimum_required从我3.12的cmake`打得很好。

我不知道,如果这个职位是非常有用的SO,但我肯定在这里学到的cmake我的教训。

© www.soinside.com 2019 - 2024. All rights reserved.