VisualStudio和gcc之间的* .dll * .a * .lib * .def兼容性 [英] Compatibility of *.dll *.a *.lib *.def between VisualStudio and gcc

查看:172
本文介绍了VisualStudio和gcc之间的* .dll * .a * .lib * .def兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很混乱。我花了很多时间阅读这个堆栈上的帖子等。仍然困惑。



我使用Qt和C ++编码。在Qt中,我使用gcc选项作为编译器。

问题是,我尝试过的许多第三方库似乎不工作。



我是.dll,.a,.lib,.def文件和库方案的新手。



问题1:



在我有限的经验图书馆的供应商很少告诉你.dll是否是用VisualStudio或gcc。这增加了很多困惑。他们几乎从来没有清楚库与什么编译器兼容。所以我会感激一些现实生活中的提示如何处理这场噩梦。几乎所有我尝试的库是OpenSource项目。我不会在这里命名,但这些都是众所周知的项目。我相信问题是我缺乏知识...



MinGW和gcc世界



问题2:

据我所知,MinGW gcc universe的动态C ++库需要这些库,对吗?

* .h

* .dll

* .a



问题3:

不幸的是,.a文件经常丢失,不起作用。这是非常混乱。如果.a文件丢失了我失去了运气?



问题4:

如果* .dll是用gcc编写的,我可以为MinGW / gcc生成.a文件吗?



问题5:
如果* .dll是用VisualStudio制作的,我可以为MinGW / gcc生成.a文件吗?



问题6:

* .dll(用MinGW / gcc制作)可能太旧,不再与较新的MinGW / gcc兼容?



问题7:

使用MinGW / gcc的Qt项目从不需要* .lib文件,对吧?这是一个VisualStudio唯一的东西,对吧?



问题8:

我不需要一个* .def文件来使用* .dll在使用MinGW / gcc的Qt项目中,



VisualStudio World 问题9:

据我所知,VisualStudio的动态C ++库需要这些:

* .h

* .dll

* .lib



对不对?同样,问题是* .lib文件几乎总是丢失。另外,没有关于库与什么编译器兼容的明确指示。所以我怎么知道它只是为VisualStudio或不是?



问题10:

如果.lib文件缺失,我不幸运?



问题11:

如果* .dll是使用VisualStudio制作的,我可以为VisualStudio生成.lib文件吗?如何?



问题12:

如果* .dll是使用MinGW / gcc制作的,我可以为VisualStudio生成.lib文件吗?如何?



问题13:

* .dll(使用VisualStudio制作)可能太旧,不再与较新的VisualStudio ?



问题14:

如果在QtCreator中选择VisualStudio编译器,它是100%与其他人编译的动态库?我相信Qt Creator中的VisualStudio编译器选项是一个假的VisualStudio编译器。



问题15:

如果在QtCreator中选择MinGW / gcc编译器,我可以与其他人使用REAL VisualStudio编译的Qt动态库?



问题16:

我不需要* .def文件来在使用MinGW / gcc的Qt项目中使用* .dll,



问题17:
我可以将使用REAL VisualStudio制作的* lib(使用* .dll和* .h)文件转换为* .a文件,所以我可以使用* .a文件与未修改的* .dll和* .h文件在一个Qt gcc项目?

解决方案

也许这是值得开始的开始,不要跳过自己,描述核心问题。从这个答案可以导出几个问题。



开始是ABI(应用程序二进制接口)。这定义了




  • 函数的调用方式。

  • 如何抛出异常

  • 如何将对象布局,例如,

  • 内置数据类型有多大

  • 函数名称如何被转换 符号

  • 如何显示类型信息

  • 标准库类的布局




大多数平台定义了一个C ABI,但不要定义一个C ++ ABI。因此,编译器定义自己的ABI(除了通常存在的C文件之外的所有内容)。这会产生在不同编译器之间不兼容的对象文件(有时甚至在同一个编译器的版本之间)。



通常,这看起来很陌生,不同的ABIs故意使用不同的名称调整,以防止意外链接一个不会工作的可执行文件。要解决这些问题,最好的办法就是使用相同的编译器构建所有组件。



如果要确定构建库所使用的编译器,可以查看在其内容使用适当的工具。我知道你要求Windows,但我只知道UNIX工具(他们可能与MingW):




  • nm看看

  • ident找到嵌入对象中的特殊字符串
  • >
  • 字符串以喜欢所有字符串

  • c ++ filt将符号解构为C ++声明



查看符号通常会产生编译器生成它们的标识。如果你经常见到他们,你甚至可以从符号本身来告诉ABI。



在这个领域还有很多,但我已经用完了耐力。 .. :-)在任何情况下,我认为这回答了上面的几个问题。


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 option for a compiler.
The problem is that many 3rd party libraries that I've tried do not seem to work.

I am new to .dll, .a, .lib, .def files and library schemes.

Question 1:

In my limited experience (I've tried 7 or 9 libraries so far), suppliers of libraries seldom tell you whether the .dll was made with VisualStudio or gcc. This adds a lot of confusion. They almost never make it clear what compiler the library is compatible with. So I would appreciate some real life tips of how to deal with this nightmare. Almost all the libraries I tried are OpenSource projects. I won't name names here, but these are well known projects. I'm sure the problem is my lack of knowledge...

MinGW and gcc World

Question2:
As far as I can tell, dynamic C++ libraries for MinGW gcc universe require these, right?
*.h
*.dll
*.a

Question 3:
Unfortunately, the .a file is often missing and the library does not work. This is very confusing. If the .a file is missing am I out of luck?

Question 4:
Can I generate the .a file for MinGW/gcc if the *.dll was made with gcc?

Question 5: Can I generate the .a file for MinGW/gcc if the *.dll was made with VisualStudio?

Question 6:
Is it possible that a *.dll (made with MinGW/gcc) is too old and no longer compatible with newer MinGW/gcc?

Question 7:
Qt projects using MinGW/gcc never need *.lib files, right? That is a VisualStudio only thing, right?

Question 8:
I don't need a *.def file to use a *.dll in a Qt projects using MinGW/gcc, right?

VisualStudio World

Question 9:
As far as I can tell, dynamic C++ libraries for VisualStudio require these:
*.h
*.dll
*.lib

Right? Again, the problem is that the *.lib file is almost always missing. Plus, no clear instructions about what compiler the library is compatible with. So how can I know that it is for VisualStudio only or not?

Question 10:
If the .lib file is missing am I out of luck?

Question 11:
Can I generate the .lib file for VisualStudio if the *.dll was made with VisualStudio? How?

Question 12:
Can I generate the .lib file for VisualStudio if the *.dll was made with MinGW/gcc? How?

Question 13:
Is it possible that a *.dll (made with VisualStudio) is too old and no longer compatible with newer VisualStudio?

Question 14:
If in QtCreator I select the VisualStudio compiler, is that 100% compatible with dynamic libraries compiled with REAL VisualStudio by someone else? I believe the VisualStudio compiler option in Qt Creator is a fake VisualStudio compiler.

Question 15:
If in QtCreator I select the MinGW/gcc compiler, can I use with Qt dynamic libraries compiled with REAL VisualStudio by someone else?

Question 16:
I don't need a *.def file to use a *.dll in a Qt projects using MinGW/gcc, right?

Question 17: Can I convert a *lib (that works with a *.dll and *.h) file made with REAL VisualStudio to a *.a file so I can use the *.a file with the unmodified *.dll, and *.h files in a Qt gcc project?

解决方案

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.

这篇关于VisualStudio和gcc之间的* .dll * .a * .lib * .def兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆