Macports Boost still incompatible with modern gcc compilers

Alec Jacobson

May 08, 2013

weblog/

I recently ran into a well known issue with the macports installation of the boost library. It seems that when you issue:
sudo port install boost
you're getting binaries of a version of boost compiled using the default compiler g++-apple-4.2. This is version of the library is unfortunately not compatible with any of the modern versions of gcc. For example this small program compiles and links correctly using g++-mp-4.7 but crashes at runtime.
#include <boost/program_options.hpp>
int main(int argc, char* argv[])
{
    boost::program_options::positional_options_description positional;
    return 0;
}
Running the code produces:
.main(33755) malloc: *** error for object 0x10f73b880: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
To fix this I forced macports to reinstall boost using my compiler of choice (g++-mp-4.7). On my computer this took 20+ minutes
sudo port -ns upgrade --force boost configure.compiler=macports-gcc-4.7
This resolves the issue above, but only for g++-mp-4.7, if I now compile my small test program using g++-apple-4.2 it fails in the same way (at least its mutually consistent).