Dll compatibility between compilers

后端 未结 9 1682
小蘑菇
小蘑菇 2021-01-02 08:35

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

相关标签:
9条回答
  • 2021-01-02 09:06

    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.

    0 讨论(0)
  • 2021-01-02 09:07

    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.

    0 讨论(0)
  • 2021-01-02 09:16

    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.

    0 讨论(0)
提交回复
热议问题