This is a temporary URL until I can be bothered setting up a blog.

Making Clang work with MinGW GCC 4.7's libstdc++

9 August 2012, 13:40 UTC

(This assumes you are compiling Clang 3.1 or 3.2 (trunk) with the official MinGW 4.7.0 distribution)

MinGW now distributes libstdc++ compiled with GCC 4.7 which now uses an ABI which Clang does not (yet) support. If you attempt to use this version of libstdc++ (or any GCC 4.7 library) with Clang, your program will likely crash at the first call of any standard library function.

I spent several hours tracking down the source of the issue, documented by a single line on the GCC 4.7 changelog (search for "thiscall").

A quick fix that only involves recompiling a single file is to change the default ABI ("itanium") to use the calling convention code from the "microsoft" ABI:

If you want to retain the default Itanium calling convention (i.e. for cross-compiling), you will have to create your own CXXABI implementation (exercise left to reader) and specify it in clang invocations for any code that interfaces with GCC 4.7 produced code.

Note: clang++ -Xclang -cxx-abi -Xclang microsoft won't help as the name mangling for symbols in libstdc++-6.dll haven't changed, only the calling convention. Even if did, there are other compatabilities between the Microsoft and GCC ABI.


Tags: Clang, MinGW, C++, libstdc++


Author: Julian Smythe