Boost.Program_options在Clang下未正确链接
Boost.Program_options not linking correctly under Clang
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互操作。
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- Clang 8 带有静态 constexpr 和数组的链接器错误 - 错误是什么以及如何解决它?
- Eclipse CDT clang 工具链 - 无法从链接器选项中删除 stdlibc++,但可以添加 libc++,E
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- std::to_chars在MacOS/clang上编译但不链接
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 程序使用boost::文件系统链接clang,但不使用gcc
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- 在这种情况下,GCC 和 clang 是否显示与 Visual Studio 相同的结果,关于语言链接?
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- Clang 3.8 错误:参数 '-fuse-ld=gold-2.25' 中的链接器名称无效
- Clang在手动链接时不会生成PROFRAW文件
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- gcc 和 clang 中 constexpr 静态成员变量的链接器错误
- 将 CLANG 构建的可执行文件与 G++-v6 构建的 Boost 库链接时出错
- CLang++ 链接器未定义的符号用于体系结构x86_64
- 在linux上链接clang/llvm库总是失败
- 在OS X上链接clang++会产生很多符号未发现错误
- 链接clang库总是未定义的符号