Compatibility of *.dll *.a *.lib *.def between VisualStudio and gcc

后端 未结 4 1827
广开言路
广开言路 2020-12-29 05:15

this is very confusing. I spent a lot of time reading posts on this on stack, etc. Still confused.

I am using Qt and C++ for coding. In Qt, I am using the gcc optio

4条回答
  •  天涯浪人
    2020-12-29 05:52

    Maybe it is worth starting at the beginning and not jump ahead of ourselves and describe the core issue. From this answers to several of the questions can be derived.

    The start is the ABI (application binary interface). This defines things like

    • how a function is called, e.g. which parameters go into which registers or what location on the stack they put
    • how exceptions are thrown
    • how objects are layed out, e.g. where the "vtable pointer" goes, what padding is used
    • how big the build-in data types are
    • how the function names are "mangled" into symbols
    • how type information is layed out
    • the layout of standard library classes
    • etc.

    Most platforms define a C ABI but don't define a C++ ABI. As a result compiler define their own ABI (for everything except the C stuff which is typically there). This yields object files which are incompatible between different compilers (sometimes even between versions of the same compiler).

    Typically, this manifests itself in strange-looking names somehow being undefined: different ABIs deliberately use different name mangling to prevent accidentally linking an executable which won't work anyway. To work around these your best bet is to build all components using the same compiler.

    If you want to determine which compiler a library is build with, you can have a look at its contents using appropriate tools. I realize that you asked for Windows but I only know the UNIX tools (they may be available with MingW):

    • nm to look at the symbol names (typically together with less or grep)
    • ar to build or inspect libraries
    • ident to find special strings embedded in the object
    • strings to fond all strings
    • c++filt to demangle symbols into their C++ declaration

    Looking at the symbols typically yields identifications of what compiler produced them. If you have seen them suffiently often, you can even tell the ABI from the symbols themselves.

    There is lots more in this area but I've run out of stamina... :-) In any case, I think this answers several of the questions above.

提交回复
热议问题