yohhoyの日記

技術的メモをしていきたい日記

C++名前マングリングの互換性

gcc(g++)のC++名前マングリング(name mangling)では、意図的に他コンパイラシステムと異なる規則を採用している。

GCCオンラインマニュアルより引用(下線部は強調)。

On many platforms, GCC supports a different ABI for C++ than do other compilers, so the object files compiled by GCC cannot be used with object files generated by another C++ compiler.

An area where the difference is most apparent is name mangling. The use of different name mangling is intentional, to protect you from more subtle problems. Compilers differ as to many internal details of C++ implementation, including: how class instances are laid out, how multiple inheritance is implemented, and how virtual function calls are handled. If the name encoding were made the same, your programs would link against libraries provided from other compilers -- but the programs would then crash when run. Incompatible libraries are then detected at link time, rather than at run time.

11.2 Interoperation - Using the GNU Compiler Collection