The reason David Schzwartz says you need an extern "C" block is because without an "C" block, the extern compiler "beckons" the name of the C function you are calling at the point you are calling. If you call the C function, not the C ++ function, the function definition in your library will not have a malformed name, so your executable will not be able to reference.
This is what you want if the function you are calling is written in C ++, since the name mangling allows you to overload the name of the function. The types of each function parameter are compactly encoded in the name of the changed function.
Initial guidance was initially provided in C ++ to allow C ++ object files to communicate with legacy linkers, rather than providing a specialized C ++ linker that has explicit support for overloaded functions.
C does not allow function name overloading, so C function names are never garbled. To provide a prototype in C ++ for a single C function, you do this:
extern "C" Foo( int theInt );
If you have an entire header file full of C function prototypes, and you want to #include this header from a C ++ source, enclose #include in an extern C block
extern "C" { #include "Foo.h" }
source share