【问题标题】:Boost.Program_options not linking correctly under ClangBoost.Program_options 在 Clang 下没有正确链接
【发布时间】:2015-12-21 00:15:34
【问题描述】:

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++ (live example) 下编译、链接和运行正确,但在 clang (live example) 下却没有错误

/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 toboost::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_template(boost::program_options::validation_error::kind_t)' clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看 调用)

问题:什么给出了?

【问题讨论】:

    标签: c++ boost g++ clang++ boost-program-options


    【解决方案1】:

    GCC C++ ABI changed in version 5 可能导致某些对象不兼容:

    用户只需要确保他们正在使用所使用的 ABI 进行构建 由它们所依赖的库。

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

    This blog post 讨论 GCC5 和 Clang 兼容性,并链接到 open LLVM bug to restore ABI interop with GCC

    【讨论】:

      猜你喜欢
      • 2016-09-06
      • 2013-11-06
      • 2016-12-29
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多