I am trying to export some functions from a DLL. Typically, I include C linkage in the function declaration so that it looks like follows:

extern "C" void someFunc(void *);

As you know, this prevents name mangling of the function by the C++ compiler. Then, I list the function in the DEF file as an exported function.

The problem is that I am trying to export a function that is also a friend of class. However, doing the following does not compile:

extern "C" friend void someFunc(void*);

But if I exclude the C linkage by not including extern "C" in the function declaration, then I must list the function with its mangled name in the DEF file. So, in the DEF file, it would look something like this:

?someFunc@@YGHPAXK@Z

This is compiler dependent and not portable.

So my question is: how do I export a function from a DLL that is also a friend of a class without mangling its name? If this is not possible, and I must export it with its mangled name, how do I find out the mangled name (so I can list it in the DEF file)?