Home >Backend Development >C++ >Why are C DLL exported function names sometimes decorated, and how can I export undecorated names?
C DLL Export: Decorated/Mangled Names
In C DLL development, it is expected that exported function names appear undecorated after compilation. However, encountering decorated function names with additional characters may raise concerns.
Cause of Decoration
The decoration seen is a result of the compiler's name mangling process. When compiling C code, the compiler modifies function names to ensure uniqueness across overloaded functions or different compilation units. This mangling includes additional characters and symbols.
Solution Using Pragma Comment
To export undecorated function names, without using a module definition file, a pragma comment can be inserted:
Alternatively, to obtain the decorated function name automatically:
Equivalent Extern "C" with Declaration Specifier
Another approach is to use extern "C" with a declaration specifier:
However, this method still results in the same decorated function name.
Eliminating the Postfix
Unfortunately, the post "=" decoration cannot be eliminated without using a module definition file or pragma comment. This postfix indicates the decorated version of the function.
Workaround for C# Applications
While the undecorated names are preferred, P/Invoke calls in C# can still be made using the decorated function name. To do so, include the fully decorated name when invoking the function.
The above is the detailed content of Why are C DLL exported function names sometimes decorated, and how can I export undecorated names?. For more information, please follow other related articles on the PHP Chinese website!