【问题标题】:How to install Boost with specified compiler (say GCC)如何使用指定的编译器安装 Boost(比如 GCC)
【发布时间】:2014-08-17 05:03:09
【问题描述】:

我想安装带有指定编译器的boost,例如我在<gcc_49_root> 中安装的gcc-4.9.1。当前的操作系统是 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...

我应该如何处理这些错误?提前致谢!

【问题讨论】:

    标签: c++ boost installation


    【解决方案1】:

    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 ;
    

    接下来从“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=) ...
    

    之后构建的 Boost 库没有错误,并且在其他 gcc4.9 编译代码中运行良好。

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

    更新(2015 年 5 月):我最近在 Yosemite (10.10.1) 上新建了 gcc 5.1.0 和 Boost 1.58.0。同样的修复对我有用。

    【讨论】:

    • 使用 David Tang 的建议,我得到了很多这种变化... gcc.link.dll stage/lib/libboost_atomic.dylib "/Users/dkick/bin/g++" -Wl,-R -Wl,"/System/Library/Frameworks/Python.framework/Versions/2.7/lib" -Wl,-R -Wl,"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /config” -o “stage/lib/libboost_atomic.dylib” -shared “bin.v2/libs/atomic/build/gcc-4.9.2/release/threading-multi/lockpool.o” ld:未知选项:-R collect2:错误:ld 返回 1 退出状态 gcc.link.dll stage/lib/libboost_system.dylib
    【解决方案2】:

    我正在使用 Mac Yosemite,这对我有用。

    打开“tools/build/example/user-config.jam”并更改

    # Configure gcc (default version).
    # using gcc ;
    
    # Configure specific gcc version, giving alternative name to use.
    

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

    然后打开“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)
    

    最后一步,编译安装

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

    现在你可以像下面这样编译你的代码

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

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

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 2016-07-18
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      相关资源
      最近更新 更多