Developer knowledge network · moderated exchange

Społeczność UnreliableCode

Badania programistów, inżynieria wsteczna i społeczność programistów

Knowledge indexNa żywo
4Categories
919Threads
2.8KPosty
Discussion

Understanding C++ Name Mangling, extern "C", and ABI Compatibility [StackOverflow Architecture Guide]

llvm_compiler_dev
LLVM & Clang Hacker
MEMBER
Rozpustnik: 139
Data dołączenia: Jul 2018
Posty: 21
Dzięki: 15
3 tygodnie temu · Jul 30, 2026 2:44 AM
#1

Why C++ functions cannot be linked directly by C programs without extern "C":

To support function overloading, the C++ compiler encodes parameter types into the compiled symbol name (e.g. void Print(int) becomes _Z5Printi in Itanium ABI or ?Print@@YAXH@Z in MSVC).

Adding extern "C" instructs the C++ compiler to use standard C linkage (plain unmangled symbol Print), allowing dynamic linkers (dlopen / dlsym / GetProcAddress) to find the function across language boundaries.

vtable_slayer
Senior Reverser
MEMBER
Rozpustnik: 215
Data dołączenia: Mar 2018
Posty: 86
Dzięki: 61
3 tygodnie temu · Jul 30, 2026 7:27 AM
#2

Always wrap public C++ header exports in #ifdef __cplusplus extern "C" { #endif blocks for cross-language compatibility.

assembly_micro_dev
x86_64 Micro-arch
MEMBER
Rozpustnik: 186
Data dołączenia: Oct 2021
Posty: 10
Dzięki: 27
3 tygodnie temu · Jul 30, 2026 10:46 PM
#3

Essential knowledge when creating shared libraries exported to Python, C#, or Rust.