开发者

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 ge开发者_如何转开发nerate 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.


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.


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


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" ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜