Posts Tagged ‘string’

Issues with C++ strings in OS X’s standard library

Monday, February 22nd, 2010

It seems that someone at Apple has turned on _GLIBCXX_FULLY_DYNAMIC_STRING in such a way that it is breaking _GLIBCXX_DEBUG builds. This means that (with some Xcode/GCC/OS X versions) if you try to use strings from the C++ standard library without enabling the _GLIBXX_FULLY_DYNAMIC_STRING preprocessor macro, your debug builds will have a runtime error similar to the following:

malloc: * error for object 0x10000a720: pointer being freed was
    not allocated * set a breakpoint in malloc_error_break to debug

In order to solve this issue from Xcode, you need to modify your build target information. Double-click your build target from the ‘Targets’ drop-down list in the left-hand column, navigate to the build tab, then scroll down to the ‘GCC – Preprocessing’ area, and enable fully dynamic strings by adding a new macro to the ‘Preprocessor Macros’ list: _GLIBCXX_FULLY_DYNAMIC_STRING=1

Feel free to leave a comment if you have any extra information on the issue (including fixes in newer versions/etc/etc).

References:
http://stackoverflow.com/questions/2234557/c-using-stdgetline-prints-pointer-being-freed-was-not-allocated
http://lists.apple.com/archives/cocoa-dev/2009/Sep/msg01199.html