Search code examples
c++commingwvtable

How to set alignment for virtual functions?


I'm developing plug-in for Win32 using mingw and crosscompilation from linux. Although my plugin successfuly loaded by application and I even got an com-interface from app, I cant call functions from there - app is crashed. I think that this is due to wrong vtable alignment of interface implementation in mingw (this worked perfectly with MSVS).

Any help will be appreciated, thanks.


Solution

  • VTable alignment (in fact, the entire VTable system at all) is completely implementation dependent. You have to use the same compiler, compiled with the same switches/settings, in order to have a workable program after linkage.

    You can't link msvc generated binaries against MinGW generated ones for this reason. Even if you got the tables to align the same, the name mangling algorithms are different, and nobody says that the two compilers would choose the same order for the individual functions within the vtable itself.

    If you need a portable interface between the two compilers, then you have to do it with a C (technically an extern "C") interface, which has a standardized ABI.