views:

336

answers:

3

Hello,

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.

+3  A: 

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

Tarydon
+1  A: 

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.

Alexander Gessler
A: 

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

Oodini
click the tick mark on the good reply
pm100
Thanks. I am so going to tick myself.
Oodini