Almost all question here on SO ends up with answers for MSVC (def file or /EXPORT link option).
However there couple that mention gcc:
How can i avoid name mangling? one mention using
asm()
in the source code. Since I'm not familiar with assembly I'm a little hesitant to use it.How do I stop name-mangling of my DLL's exported function? one mentions using
-Wl,--kill-at
option during the compilation/linking. However, I can't find anything like this in any gcc or link man pages online.
So, is there any way to avoid name mangling in C++ without using extern "C"
?
Thank you.
[EDIT]
class Base
{
public:
virtual void Foo() = 0;
};
class Derived : public Base
{
public:
virtual void Foo() {};
};
extern "C" Base *MyExportedFunc()
{
Base *pb = new Derived();
return pb;
}
Without extern "C" MyExportedFunc() will have C++ linkage and the name will be mangled. And so I will not be able to simply call it from C++ code. With extern "C" the function is C-linkage. But then the function will not know about Base -> Derived relationship. And therefore the caller of the function will just see an address in the memory. It is a C function.
Hope it is clear now.
[/EDIT]