Possible Duplicate:
GCC 4.0, 4.2 and LLVM ABI Compatibility
As per subject, are both C++ ABIs compatible?
I.e. can a binary (Shared Object) generated with the former be used and linked with the latter (and vice-versa)?
Cheers
clang, modulo bugs, is fully C++ ABI compatible with GCC (they both follow the intervendor Itanium ABI) on unix systems. Make sure you use the same standard library for all components because libstdc++ and libc++ are different implementations with completely different object layouts.
gcc and g++ are the traditional GNU compilers for C and C++ code. Recently, clang (and clang++) using LLVM has been gaining popularity as an alternative compiler.
(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.
These details are defined as the compiler Application Binary Interface, or ABI. From GCC version 3 onwards the GNU C++ compiler uses an industry-standard C++ ABI, the Itanium C++ ABI. The GNU C++ compiler, g++, has a compiler command line option to switch between various different C++ ABIs.
According to the clang libc++ page, they're targeting
ABI compatibility with gcc's libstdc++ for some low-level features such as exception objects, rtti and memory allocation.
which seems to imply that they're not targeting 100% compatibility. For example, on that page they also say:
From years of experience (including having implemented the standard library before), we've learned many things about implementing the standard containers which require ABI breakage and fundamental changes to how they are implemented. For example, it is generally accepted that building std::string using the "short string optimization" instead of using Copy On Write (COW) is a superior approach for multicore machines (particularly in C++'0x, which has rvalue references). Breaking ABI compatibility with old versions of the library was determined to be critical to achieving the performance goals of libc++.
I believe that GCC is still using a reference-counted COW, so it appears that clang isn't worried about ABI compatibility with std::string
(either with older clang compiled binaries or with GCC).
It seems to be compatible. Clang also has a project for their own C++ runtime, and it states that it is low-level compatible with GNU stdlibc++. I just tried a small example program, where I compiled one file with clang++, and compiled and linked the main program and with g++. No problem so far, but the program was rather simple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With