使用 LLVM 将问题与 OSX 上的 boost::program_options 链接起来 [英] Linking troubles with boost::program_options on OSX using LLVM

查看:24
本文介绍了使用 LLVM 将问题与 OSX 上的 boost::program_options 链接起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 Boost 1.49 的问题,我在 C++ 程序中无法通过链接阶段.我已切换到 C++ (-std=c++11 -libc=libc++),它适用于另一段代码(也使用 boost).Boost 是使用自制软件安装的:

I'm having trouble getting through the linking phase in my C++ program due to problems with Boost 1.49. I have switched to C++ (-std=c++11 -libc=libc++) which works fine for another piece of code (which also uses boost). Boost was installed using homebrew with:

brew install boost --universal --with-mpi --with-icu

问题始于boost::program_options.我收到这样的链接错误:

The trouble starts with boost::program_options. I get the link errors like this:

  "boost::program_options::validate(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, int)", referenced from:

... etc. ...

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这有点奇怪,因为在使用的库上执行 nm 显示,该符号似乎在那里:

This is a little strange, because doing an nm on the library used reveals, that the symbol appears to be there:

nm -U /usr/local/lib/libboost_program_options-mt.dylib  | grep validate
0000000000019880 - 01 0000   FUN __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISbIwSt11char_traitsIwESaIwEESaIS7_EEPSsi
0000000000019880 T __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISbIwSt11char_traitsIwESaIwEESaIS7_EEPSsi
00000000000199e0 - 01 0000   FUN __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISbIwSt11char_traitsIwESaIwEESaIS7_EEPbi
00000000000199e0 T __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISbIwSt11char_traitsIwESaIwEESaIS7_EEPbi
0000000000019930 T __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISsSaISsEEPSsi
0000000000019930 - 01 0000   FUN __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISsSaISsEEPSsi
0000000000019c70 - 01 0000   FUN __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISsSaISsEEPbi
0000000000019c70 T __ZN5boost15program_options8validateERNS_3anyERKSt6vectorISsSaISsEEPbi

我已经尝试通过在安装前相应地设置 CXX 和 CXX_FLAGS 来诱使自制软件使用 clang 而不是 gcc 编译 boost.不过我不确定我成功了.

I have already tried coaxing homebrew to compile boost with clang instead of gcc by setting CXX and CXX_FLAGS accordingly prior to installation. Not sure I succeeded though.

不胜感激.

推荐答案

您将需要使用 clang 和 std11 标志重新编译 boost,libc++ 库与 OSX 中安装的 libstdc++ 二进制不兼容(gcc 之前的非常早期版本更改为 gpl3).如果您的 clang 版本是 3.1 或更高版本,那么您可以使用(否则将 c++11 更改为 c++0x 以获取早期版本).

You will need to recompile boost with clang and std11 flags, the libc++ library is not binary compatible with the installed libstdc++ in OSX (very early version of gcc prior to changing to gpl3). If your version of clang is 3.1 or over then you can use (otherwise change c++11 to c++0x for earlier versions).

./bootstrap.sh
mkdir build
sudo ./bjam toolset=clang cxxflags="-std=c++0x -stdlib=libc++" variant=release link=static threading=multi runtime-link=shared --build-dir=Build --layout=system --without-mpi --without-python install --prefix=/usr/local 

您当然可以随意更改其中任何一个,除了

You can of course alter any of these as you wish except

toolset=clang cxxflags="-std=c++0x -stdlib=libc++"

toolset=clang cxxflags="-std=c++0x -stdlib=libc++"

这应该对你有用.

这篇关于使用 LLVM 将问题与 OSX 上的 boost::program_options 链接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆