What is 'Name Mangling', and why is extern "C" necessary when linking with C code?
Last updated
Name mangling encodes a function's namespace, class, and parameter types into its linker symbol so overloads like
foo(int)andfoo(double)get distinct symbols. The scheme is compiler-specific.C does not overload and emits plain names, so
extern "C"disables mangling to make C++ look up the C symbol. Without it you get unresolved-symbol link errors.