The role of extern "C" of the

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/baiyibin0530/article/details/90767131

extern "C" indicates that this can only be called C language, in addition to this, there is no more meaning. 
Because there will be a mechanism to break up the called function name C language compiler and C ++ are different, C ++, such as function: int add (int a, int b) after C ++ inside the compiler, it is not int add (int a, int b), but similar to: int add @ WEROIUERH (int a , int b) of the function name, but is random, if not extern "C", C language simply can not call, but in C ++ which can pass the @ order to call.

__declspec (dllexport) output function of time, with loadlibrary then why not? 
The key is you have to know the name of the output symbols. 
Since c ++ has function overloading and does not uniquely identify a function by function name, so the use of the system will be added parameter information c ++ compiled function of the internal modifier in the target code in and return value information, this time you can estimate the correct name of it? 
If you add extern "C" is used to compile c manner, internal functions in the target code modifier is _ function name, you can call as long as the function name

Because there are a C ++ function overloading, so at compile time, the compiler will you write, that is the function you wish to export 
back with some information about the parameters, that is the real name of the function you want to export and Different. 
Also, because the C language does not function overloading, so with the EXTERN "C" means that tells the compiler not to function as modified in accordance with the C ++ 
name. 

Recommended module definition file .def file to write DLL, so you can ensure the purity of exported functions.

 

Guess you like

Origin blog.csdn.net/baiyibin0530/article/details/90767131