简体   繁体   English

如何使用指定的编译器安装Boost(例如GCC)

[英]How to install Boost with specified compiler (say GCC)

I would like to install boost with specified compilers, such as the gcc-4.9.1 that I have installed in <gcc_49_root> . 我想使用指定的编译器来安装boost ,例如我在<gcc_49_root>安装的gcc-4.9.1 The current OS is Mac OS X 10.9.4, but I would like this installation process to work on other OS. 当前的操作系统是Mac OS X 10.9.4,但是我希望此安装过程可以在其他OS上运行。 The documentation of boost is quite opaque about this scenario. 关于这种情况, boost的文档非常模糊。 What I have tried is as following: 我尝试过如下:

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

Insert using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : ; using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : ;插入using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : ; into project-config.jam . project-config.jam

$ ./b2 --prefix=<...> toolset=gcc-4.9.1 install

But encountered the errors: 但是遇到了错误:

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

What should I do with these errors? 这些错误该怎么办? Thanks in advance! 提前致谢!

Apple's linker ld(ld64) is different from other UNIX/GNU linkers and does not support some options, such as -h(soname), --start-group, --end-group, etc,. 苹果的链接器ld(ld64)与其他UNIX / GNU链接器不同,并且不支持某些选项,例如-h(soname),--start-group,--end-group等。 Those errors you got("unknown option") were the results of trying to pass non-supported flags to Apple's ld when you specify the gcc toolset. 您得到的那些错误(“未知选项”)是在您指定gcc工具集时尝试将不支持的标志传递给Apple ld的结果。

The way I hacked mine was to first include "darwin" in the project config file: 我入侵我的方式是首先在项目配置文件中包含“ darwin”:

using gcc : 4.9.1 : <gcc_49_root>/bin/g++-4.9 : <linker-type>darwin ;

Next removing the non-supported flags from {BOOST_DIR}/tools/build/src/tools/gcc.jam, from the long command in the "actions link.dll bind LIBRARIES" block: 接下来,从“ actions link.dll bind LIBRARIES”块中的长命令中删除{BOOST_DIR} /tools/build/src/tools/gcc.jam中不受支持的标志:

remove/comment out this portion:
... $(HAVE_SONAME)-Wl,$(SONAME_OPTION)$(SPACE)-Wl,$(<[-1]:D=) ...

Afterwards the Boost libraries built without errors and worked fine in other gcc4.9 compiled codes. 此后,Boost库得以正确构建,并在其他gcc4.9编译代码中运行良好。

$ ./bootstrap.sh --with-toolset=gcc 
$ ./b2 --toolset=gcc-4.9.1

UPDATE (May 2015): I recently did a new built of gcc 5.1.0 and Boost 1.58.0 on Yosemite (10.10.1). 更新(2015年5月):我最近在优胜美地(10.10.1)上新建了gcc 5.1.0和Boost 1.58.0。 Same fix worked for me. 相同的修复方法对我有用。

I am using Mac Yosemite and this worked for me. 我正在使用Mac Yosemite,这对我有用。

Open "tools/build/example/user-config.jam" and change 打开“工具/构建/示例/user-config.jam”并进行更改

# Configure gcc (default version).
# using gcc ;

# Configure specific gcc version, giving alternative name to use.

using darwin : 5 : g++-5 ; 使用darwin:5:g ++-5;

Then open "tools/build/src/tools/darwin.jam" then delete below line (this step may not be required. just try both way); 然后打开“ tools / build / src / tools / darwin.jam”,然后删除下面的行(可能不需要此步骤。只需尝试两种方式);

"$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)

As last step, compile and install 最后一步,编译并安装

$ ./bootstrap.sh --with-libraries=all --with-toolset=darwin --prefix=/usr/local/boost_for_gcc
$ ./b2
$ ./b2 install

Now you can compile your code like below 现在您可以像下面那样编译代码

$ g++ -o main main.cpp -L/usr/local/boost_for_gcc/lib -I/usr/local/boost_for_gcc/include -lboost_regex

Reference: http://qiita.com/misho/items/0c0b3ca25bb8f62aa681 参考: http : //qiita.com/misho/items/0c0b3ca25bb8f62aa681

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM