我想安装 boost
使用指定的编译器,例如 gcc-4.9.1
我已经安装在<gcc_49_root>
.当前操作系统是 Mac OS X 10.9.4,但我希望此安装过程可以在其他操作系统上运行。 boost
的文档对这种情况非常不透明。我尝试过的如下:
$ ./bootstrap.sh
-n Building Boost.Build engine with toolset darwin...
tools/build/src/engine/bin.macosxx86_64/b2
-n Detecting Python version...
2.7
-n Detecting Python root...
/System/Library/Frameworks/Python.framework/Versions/2.7
-n Unicode/ICU support for Boost.Regex?...
not found.
Generating Boost.Build configuration in project-config.jam...
插入 using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : ;
进入project-config.jam
.
$ ./b2 --prefix=<...> toolset=gcc-4.9.1 install
但是遇到错误:
Jamfile</Users/dongli/Shares/works/packman/test/packages/Boost/boost_1_56_0/libs/context/build>.gas64 bin.v2/libs/context/build/gcc-4.9.1/release/address-model-64/architecture-x86/threading-multi/asm/make_x86_64_sysv_macho_gas.o
FATAL:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../libexec/as/x86_64/as: I don't understand '-' flag!
clang: error: no input files
cpp -x assembler-with-cpp "libs/context/src/asm/make_x86_64_sysv_macho_gas.S" | as --64 -o "bin.v2/libs/context/build/gcc-4.9.1/release/address-model-64/architecture-x86/threading-multi/asm/make_x86_64_sysv_macho_gas.o"
...failed Jamfile</Users/dongli/Shares/works/packman/test/packages/Boost/boost_1_56_0/libs/context/build>.gas64 bin.v2/libs/context/build/gcc-4.9.1/release/address-model-64/architecture-x86/threading-multi/asm/make_x86_64_sysv_macho_gas.o...
gcc.link.dll bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/libboost_atomic.dylib
ld: unknown option: -h
collect2: error: ld returned 1 exit status
"/usr/local/opt/gcc/bin/g++-4.9" -o "bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/libboost_atomic.dylib" -Wl,-h -Wl,libboost_atomic.dylib -shared -Wl,--start-group "bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/lockpool.o" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group
...failed gcc.link.dll bin.v2/libs/atomic/build/gcc-4.9.1/release/threading-multi/libboost_atomic.dylib...
我应该如何处理这些错误?提前致谢!
最佳答案
Apple 的链接器 ld(ld64) 与其他 UNIX/GNU 链接器不同,不支持某些选项,例如 -h(soname)、--start-group、--end-group 等。你得到的那些错误(“未知选项”)是在你指定 gcc 工具集时试图将不受支持的标志传递给 Apple 的 ld 的结果。
我破解我的方法是首先在项目配置文件中包含“darwin”:
using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : <linker-type>darwin ;
下一步从 {BOOST_DIR}/tools/build/src/tools/gcc.jam 中删除不受支持的标志,从“actions link.dll bind LIBRARIES” block 中的长命令:
remove/comment out this portion:
... $(HAVE_SONAME)-Wl,$(SONAME_OPTION)$(SPACE)-Wl,$(<[-1]:D=) ...
之后构建的 Boost 库没有错误,并且在其他 gcc4.9 编译代码中运行良好。
$ ./bootstrap.sh --with-toolset=gcc
$ ./b2 --toolset=gcc-4.9.1
更新(2015 年 5 月):我最近在优胜美地 (10.10.1) 上新建了 gcc 5.1.0 和 Boost 1.58.0。同样的修复对我有用。
关于c++ - 如何使用指定的编译器(例如 GCC)安装 Boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25346443/