Search code examples
c++visual-c++dllexport

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.


Solution

  • 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.