【问题标题】:Boost Linker Issues提升链接器问题
【发布时间】:2021-02-02 20:51:45
【问题描述】:

我正在使用 Boost 库,但遇到了一些链接器问题。目前我的代码正在输出这个:

架构 x86_64 的未定义符号: “boost::program_options::to_internal(std::__1::basic_string const&)”,引用自: std::__1::vector<:__1::basic_string std::__1::char_traits std::__1::allocator>, std::__1::allocator<:__1::basic_string std::__1::char_traits std::__1::allocator>> > boost::program_options::to_internal<:__1::basic_string std::__1::char_traits std:: __1::allocator> >(std::__1::vector<:__1::basic_string std::__1::char_traits std::__1::allocator>, std::__1::allocator > > const&) 在 train_model_main.cc.o “boost::program_options::variables_map::variables_map()”,引用自: _main in train_model_main.cc.o(列表继续)

在我的代码底部是这样写的:

ld:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

我正在尝试使用 Boost 中的 program_options 库,但链接步骤似乎失败了。以下是我在 CMake 文件中的链接方式:

find_package(Boost 1.73.0 COMPONENTS program_options REQUIRED)
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    add_executable(main ./apps/something.cc)
    target_link_libraries( main program_options)
endif()

我相信我正确链接了库,那么可能导致此问题的原因是什么?

【问题讨论】:

    标签: boost linker-errors clion boost-program-options


    【解决方案1】:

    我将复制并粘贴 cmake 话语中的答案: https://discourse.cmake.org/t/boost-linker-issues/2030

    “我相信我正确链接了库”不幸的是没有。您需要引用完整的目标名称,包括带有 Boost::program_options 的命名空间前缀。并且您可以省略显式添加 Boost_INCLUDE_DIRS,因为目标定义确实包含此内容信息。所以你的线条看起来像:“ - Volker Enderlein

    if(Boost_FOUND)
        add_executable(main ./apps/something.cc)
        target_link_libraries(main PUBLIC Boost::program_options)
    endif()
    

    【讨论】:

    • 刚试过这个,但没用。将尝试在演讲中提问。
    【解决方案2】:

    架构不匹配是这里的问题。将您正在构建的应用程序的编译与 boost 程序选项相匹配

    How do you build the x64 Boost libraries on Windows?

    根据您的情况,地址需要设置为 64 或使用 64 位二进制文​​件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2012-12-17
      • 2023-03-24
      • 2010-09-11
      • 2011-07-11
      • 2013-03-21
      相关资源
      最近更新 更多