Boost.Program_options在Clang下未正确链接

Boost.Program_options not linking correctly under Clang

本文关键字:链接 Clang Program options Boost      更新时间:2023-10-16

Boost.Program_options文档中的以下初始示例

// Copyright Vladimir Prus 2002-2004.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
/* The simplest usage of the library.
 */
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <iterator>
using namespace std;
int main(int ac, char* av[])
{
    try {
        po::options_description desc("Allowed options");
        desc.add_options()
            ("help", "produce help message")
            ("compression", po::value<double>(), "set compression level")
        ;
        po::variables_map vm;        
        po::store(po::parse_command_line(ac, av, desc), vm);
        po::notify(vm);    
        if (vm.count("help")) {
            cout << desc << "n";
            return 0;
        }
        if (vm.count("compression")) {
            cout << "Compression level was set to " 
                 << vm["compression"].as<double>() << ".n";
        } else {
            cout << "Compression level was not set.n";
        }
    }
    catch(exception& e) {
        cerr << "error: " << e.what() << "n";
        return 1;
    }
    catch(...) {
        cerr << "Exception of unknown type!n";
    }
    return 0;
}

在g++(实时示例)下正确编译、链接和运行,但在clang(live示例

/tmp/main-47ef95.o:在功能中boost::program_options::typed_value<double, char>::name() const': main.cpp:(.text._ZNK5boost15program_options11typed_valueIdcE4nameEv[_ZNK5boost15program_options11typed_valueIdcE4nameEv]+0x49): undefined reference to升压::program_options::arg'/tmp/main-47ef95.o:在功能中boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)': main.cpp:(.text._ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i[_ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i]+0x39): undefined reference to boost::program_options::validation_error::get_templateclang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

问题:给出了什么?

GCC C++ABI在版本5中发生了更改,这可能会导致一些对象不兼容:

用户只需要确保他们使用的是ABI

我认为您的boost版本可能是使用GCC 5构建的(CoLiRu安装了5.2),并且生成的库与clang++对象不兼容。

这篇博客文章讨论了GCC5和Clang的兼容性,并链接到一个打开的LLVM错误,以恢复与GCC的ABI互操作。

相关文章: