c++ - 使用 LLVM 在 OSX 上将问题与 boost::program_options 联系起来

标签 c++ boost c++11 osx-lion clang

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

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

麻烦始于 boost::program_options。我收到这样的链接错误:

  "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 显示,符号似乎在那里:

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。不确定我是否成功了。

不胜感激。

最佳答案

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

./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 

您当然可以根据需要更改其中的任何内容,除了

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

这应该适合您。

关于c++ - 使用 LLVM 在 OSX 上将问题与 boost::program_options 联系起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11081818/

相关文章:

c++ - 从位域获取完整值

c++ - 在不更改接口(interface)的情况下向对象添加功能

c++ - 为什么这个错误 : no function for call to 'Class11::Class11( )'

c++ - 如何在没有提升的情况下将 C++11 代码转换为 C++98?

C++ 格式化输入必须匹配值

C++/BOOST:condition_variable::wait( )/notify( ) 是否确保线程等待的顺序?

c++ - Boost 计划选项示例

c++ - Boost Asio 多线程 TCP 同步服务器

c++ - 有模板复制构造函数时不生成默认构造函数

c++ - 这是非多态继承的一个很好的理由吗?