C language In order to solve the polymorphic issue of the function, the C language will join the function name and parameters to generate a middle function name, and the C language will not, so the corresponding function is not found when the link is caused. At this time The C function needs to use Extern "C" to specify, this tells the compiler, keep my name, do not generate an intermediate function name for links. Here is a standard way of writing: // On the head of .h file #ifdef __cplusplus # {__cplusplusextern "c" {#ndif #Endif / * __cplusplus * / ... //.h file ended #ifdef __cplusplus #if __cplusplus} # endif # endif / * __cplusplus * /
A small game on a text. If the code text compiled by __cplusplus then compiler is: extern "c" {int sum (int Num1, int Num2); int Mult (int Num1, int Num2);} If you don't define __cplusplus if you compile Is: int sum (int Num1, int Num2); int Mult (int Num1, int Num2);