How to install Boost with specified compiler (say GCC)

前端 未结 2 692
渐次进展
渐次进展 2020-12-30 17:46

I would like to install boost with specified compilers, such as the gcc-4.9.1 that I have installed in . The curren

相关标签:
2条回答
  • 2020-12-30 18:30

    I am using Mac Yosemite and this worked for me.

    Open "tools/build/example/user-config.jam" and change

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

    using 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);

    "$(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

    0 讨论(0)
  • 2020-12-30 18:36

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

    The way I hacked mine was to first include "darwin" in the project config file:

    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:

    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.

    $ ./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). Same fix worked for me.

    0 讨论(0)
提交回复
热议问题