Mac OS X and static boost libs & # 8594; std :: string fail

I am having very strange problems with static boost libraries (Boost 1.45.0-2 from MacPorts compiled as fat / universal libraries (x86 / x86_64) on Mac OS X 10.6.6 with GCC 4.5.

Error message

main(78485) malloc: *** error for object 0x1000e0b20: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug [1] 78485 abort (core dumped) 

and a tiny bit of sample code that will cause this problem:

 #define BOOST_FILESYSTEM_VERSION 3 #include <boost/filesystem.hpp> #include <iostream> int main (int argc, char **argv) { std::cout << boost::filesystem::current_path ().string () << '\n'; } 

This problem always occurs when linking static boost libraries in binary format. Linking will dynamically work fine.

More info:

Checked / used version of gcc: Apple GCC 4.2.1 (works / works), MacPorts GCC 4.5.2 (does not work)

flags checked / used : -fPIC, -fPIC -g, -fPIC -g -ggdb3 -gdwarf-2 -O0

gdb output with MP GCC 4.5.2 / any flags above:

 (gdb) run Starting program: /Users/ionic/crashtest/bin/ctest Reading symbols for shared libraries .++++++++++++++++++++++.................................................................................................................. done ctest(80366) malloc: *** error for object 0x100fe6b20: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Program received signal SIGABRT, Aborted. 0x00007fff81a4e616 in __kill () (gdb) bt full #0 0x00007fff81a4e616 in __kill () No symbol table info available. #1 0x00007fff81aeecca in abort () No symbol table info available. #2 0x00007fff81a066f5 in free () No symbol table info available. #3 0x0000000100f763e9 in std::string::_M_mutate () No symbol table info available. #4 0x0000000100f7644c in std::string::_M_replace_safe () No symbol table info available. #5 0x0000000100f77edd in std::string::replace () No symbol table info available. #6 0x000000010000713d in std::string::_M_rep () at /usr/include/c++/4.2.1/bits/basic_string.h:1412 to = (string &) Cannot access memory at address 0x0 

It seems to work fine with Apple's GCC version (quite old), but it doesn’t work well with the new MacCC GCC build.

otool -L ctest:

 ./../../bin/ctest: /opt/local/lib/gcc45/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.14.0) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0) /opt/local/lib/gcc45/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1) 

I saw various reports for a fairly similar OS X error with GCC 4.2 and the _GLIBCXX_DEBUG macro, but this one seems even more general since I don't use Xcode or install the macro (even undefining it does not help. I tried this to make sure that it really not related to this problem.) Not at all like this problem, since the same code works fine with Apple GCC.

Since Apple GCC does not include any C ++ 0x features, I would really like to use the stable version of GCC for now.

Does anyone have any clue why this is happening or maybe even be a solution (and not using a dynamic library workaround)?

Yours faithfully,

Mihai

+6
c ++ boost static-libraries macos
source share
1 answer

The problem was that Boost was built using Apple GCC 4.2.1, while I was building the project using a different compiler.

As I tried to link Boost static libraries, GCC 4.2.1 libstdC ++ was added to Binary. However, at the same time, another version of GCC was linked in libstdC ++, and namespace problems were inherent, so incorrect functions were called, etc.

The simplest fix is ​​to rebuild Boost with your target version of GCC and try again to create your program (for example, using the built-in Boost.)

Be careful: do not try to change the compiler used by MacPorts to create Boost (this is not even easy), or a system crash may occur. Instead, create Boost yourself.

+7
source share

All Articles