Is there some way to make c++ dlls built with diffrent compilers compatible with each other? The classes can have factory methods for creation and destruction, so each compi
Your problem is maintaining ABI. Though same compiler but different versions you still want to maintain the ABI. COM is one way of solving it. If you really want to understand how COM solves this then check out this article CPP to COM in msdn which describes the essence of COM.
Apart from COM, there are other (one of the oldest) ways to solve ABI like using Plain old data and opaque pointers. Look at Qt/KDE library developers way of solving ABI.
You can as long as you only use extern "C"
functions.
This is because the "C" ABI is well defined, while the C++ ABI is deliberately not defined. Thus each compiler is allowed to define its own.
In some compilers the C++ ABI between different versions of the compiler or even with different flags will generate an incompatable ABI.
The problem with your code that causes the crash is virtual destructors in the interface definition:
virtual ~IRefCounted(){}
...
virtual ~IClass(){}
Remove them and everything is going to be ok. The problem is caused by the way the virtual function tables are organized. MSVC compiler ignores the destructor, but GCC adds it as a first function in the table.
Have a look at the COM interfaces. They don't have any constructors/destructors. Never define any destructors in the interface and it's going to be ok.