How to change/check the compiler used by b2 when compiling Boost?

10,279

Leave user-config.jam in \boost\tools\build\v2. Note that lines beginning from # are comments. Your configuration should look like this (assuming that g++ is located at full/Path/ and named g++-mp4.8):

  using gcc : macports :
         full/Path/g++-mp4.8 :
  <compileflags>--sysroot=full/path/to/sysroot
  ;

You might also need to set <archiver> and <ranlib> options to allow Boost.Build locating ar and ranlib.

Invoke this configuration in b2 line like this:

b2 toolset=gcc-macports

Share:
10,279
daj
Author by

daj

Updated on June 04, 2022

Comments

  • daj
    daj almost 2 years

    Due to a problem like similar to this:

    Mac OS X and static boost libs -> std::string fail

    Namely I get a run-time error "pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug" when calling the boost filesystem directory iterator constructor. My impression is this can happen if boost and the program are compiled with different compilers.

    So I'm trying to re-compile boost libs using the same compiler I'm using for my programs, namely macports gcc (g++-mp-4.8). Based on some online instructions, my understanding is that I edit tools/build/v2/user-config.jam, to specify the compiler, so it now says:

    # Configure gcc (default version).
    # using gcc ;
    
    # Configure specific gcc version, giving alternative name to use.
    # using gcc : 4.8 : g++-mp-4.8 ;
    

    I copy user-config.jam to my home directory, rerun bootstrap.sh and rerun b2. However I still get my error that comes up ("pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug"). Is this the right procedure for specifying the compiler to use to compile? How do I check to see which compiler boost is actually using when I run b2?

  • daj
    daj about 11 years
    What's the relationship between specifying the compiler in user-config.jam and specifying it to ./configure ( boost.org/doc/libs/1_53_0/libs/config/doc/html/index.html )? I found this a bit confusing. Is this just two ways to specify the same thing or is configure completely unrelated?
  • daj
    daj about 11 years
    One other thing that I found strange was that when I uncommented what I wrote above and used toolset=gcc, I wound up with lots of linker errors complaining about undefined command line arguments to ld. I tried changing it to "darwin : 4.8 : gcc-mp-4.8" and used toolset=darwin and somehow that got rid of the linker errors (although there were a lot of warnings about "typedef '[XXX]' locally defined but not used").
  • Igor R.
    Igor R. about 11 years
    @daj 1) Boost.Config documentation says: "This configure script only sets up the Boost headers for use with a particular compiler. It has no effect on Boost.Build, or how the libraries are built". 2) When you invoke toolset=gcc, it goes to the default gcc configuration; what you actually mean is toolset=gcc-4.8 - this would invoke the section that starts with using gcc : 4.8 : g++-mp-4.8 ;
  • Igor R.
    Igor R. about 11 years
    @daj see the following link for details: boost.org/boost-build2/doc/html/bbv2/overview/…