简体   繁体   中英

DLL : export as a C/C++ function?

I generated a DLL in Visual from a C++ code. Dependency Walker sees 3 functions exported as C functions.

I made an SCons project to do the generate the DLL, and 2 of the 3 functions are not seen as C functions.

What makes a function seen as a or C++ function, without modifying the code ? It must be in the compilation/linking options, but I didn't find any relevant thing.

The function are prefixed by a macro : AM_LIB_EXPORT

In the .h, I have :

#ifdef _WIN32
#define AM_LIB_EXPORT __declspec(dllexport)
#else
#define AM_LIB_EXPORT
#endif // _WIN32

Thanks.

Is this a name mangling issue? If you don't use extern "C" around your function declarations, they will get name-mangled.

What makes a function seen as a or C++ function, without modifying the code ?

A function compiled by a C++ compiler is automatically a 'C++-function' and name-mangling occurs to resolve C++ features such as namespaces and overloading. In order to get 'C' export names, one must use the aforementioned extern "C" qualifier in the function declaration. Alternatively a huge extern "C" { .. } block around the header containing the prototypes.

If this does not solve your issue, its maybe related to dllimport/dllexport. If you #define AM_LIB_EXPORT __declspec(dllexport) in your DLL build, you'll typically also need to make it dllimport for apps linking against your DLL in order for the linker to know where to fetch the symbols from.

I found the reason :

The export was also added as additionnal command line option (/EXPORT). In this case, it is exported as a C function. I don't understand why...

I removed this additionnal command line switch.

Thank you all.

I still don't know how to mark a thread as "resolved" ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM