【问题标题】:tell CMake to link to Boost in a custom folder告诉 CMake 在自定义文件夹中链接到 Boost
【发布时间】:2020-10-01 18:41:37
【问题描述】:

我正在尝试在自定义目录中安装 boost。我做到了:

cd boost_dir
./bootstrap.sh --prefix=/custom_dir
./b2

现在我想做的是告诉 CMake 指向那个库。为此,我补充说:

set(BOOST_ROOT "/custom_dir")
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(myProject ${Boost_LIBRARIES})

CMake 显然在该目录中找到了提升:

cmake .                                                                                                                                                                                     
-- Found Boost: /custom_dir (found suitable version "1.66.0", minimum required is "1.66") found components: program_options                                                                                 -- Configuring done                                                                                                                                                                                                           
-- Generating done                        
-- Build files have been written to: /my_project

但是,在编译时,我仍然得到:

undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'

一些答案​​指出,boost 必须使用与我正在使用的程序相同的编译器进行编译。但是,我不确定我上面所做的步骤是否真的编译了 boost 或只是复制了未压缩的库?

另外,它是否使用了路径解析的 g++ 或系统默认 /usr/bin 中的东西?原因是我没有 root 访问权限,并且还在自定义目录中安装了更新的 GCC。我已将我的 PATH 指向更新后的 g++。

【问题讨论】:

    标签: c++ gcc boost cmake g++


    【解决方案1】:

    事实证明,GCC 版本是正确的,但只有当我使用静态链接编译 Boost 并告诉 CMake 静态链接时它才会起作用。我尝试了动态链接(为我的目标应用程序编译 Boost 和设置 CMake),但由于某种原因它不起作用。

    只需确保使用相同的 ABI 选项进行编译即可。

    【讨论】:

      猜你喜欢
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      相关资源
      最近更新 更多