链接:.a,.lib和.def文件 [英] Linking : .a, .lib and .def files

查看:120
本文介绍了链接:.a,.lib和.def文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GNU binutils在Windows上的程序集中构建dll.

I am building a dll from assembly on Windows using the GNU binutils.

我知道可以在加载可执行文件时或在运行时(使用LoadLibrary api调用)加载dll.

I know that the dll can be either loaded when the executable is loaded or at run-time (using the LoadLibrary api call).

对于加载时加载,我似乎只需要dll文件:不需要.a,.lib或.def文件.我想知道这些文件格式代表什么以及它们的目的是什么.

For load-time loading, I seem to be only needing the dll file : no .a, .lib or .def file is needed. I wondered what these file format represent and what purpose do they serve.

我所知道的以及一些特定的问题:

What I know and some specific questions :

  • .a是Unix上通常用于静态库的扩展名. .a文件是使用GNU的 --out-implib 选项生成的ld.据说这是一个进口图书馆",足够公平.然后的问题是如果链接时不需要导入库,对我有什么好处?"

  • .a is the extension generally used for static library on Unix. .a files are generated with the --out-implib option of GNU ld. It is said to be an "import library", fair enough. The question is then "What good is an import library to me if I don't need it when linking ?"

.lib是Windows上用于静态库的扩展,并且据Wikipedia所述,它还用作Windows下的导入库",因此我强烈怀疑它们只是binutils调用的别称.一个文件.是/否?

.lib is the extension used for static library on Windows, and according to wikipedia, is also used as "import library" under windows, so I strongly suspect they're just another name for what the binutils call .a files. True/false ?

在所有页面上,我都能找到.def文件列出了dll导出符号的点.

All pages I can find points that .def files list the exported symbol of the dll. Isn't that somewhat similar to what an "import library" is supposed to do ?

此外,我在此处读到,使用.def文件可以替代在源文件中手动指定导出(我做了).但是我还记得阅读(找不到参考文献).def文件提供了索引(常规)添加到导出的符号中,从而可以更快地加载运行时.是这样吗?

Also, I read here that using .def files is an alternative to manually specifying exports in the source file (which I did). But I also remember reading (cannot find reference back) .def file supply an index (ordinal) into the exported symbols, allowing for faster run-time loading. Is that so ?

推荐答案

Linux上的静态库具有.a文件扩展名. Windows上的静态库具有.lib文件扩展名. Windows上的动态库具有.dll扩展名;为了链接DLL,需要导入库.导入库是静态库.它包含加载DLL所需的代码.现在,您正在使用GCC(不是cl.exe)在Windows上进行编译. GCC还有另一个用于导入库的文件扩展名约定,如

Static libraries on Linux have the .a file extension. Static libraries on Windows have the .lib file extension. Dynamic libraries on Windows have the .dll extension; in order to link against a DLL, an import library is required. The import library is a static library. It contains the code required to load the DLL. Now you're using GCC (not cl.exe) to compile on Windows. GCC has another file extension convention for import libraries, it "should be called *.dll.a or *.a", as explained in the doc for the --out-implib you referred to.

导入库(带有MSVC的.lib或带有GCC的.dll.a)是静态库:它们包含用于加载DLL的代码. 前几天我有同样的问题.

Import libraries (.lib with MSVC or .dll.a with GCC) are static libraries: they contain the code to load the DLL. I had the same question the other day.

DLL可能具有导出的功能和未导出的功能.导入库必须知道要导出哪些功能,哪些不导出.告诉它的一种方法是DEF文件.

A DLL may have functions that are exported and functions that are not exported. An import library has to know which functions are exported and which aren't. One of the means of telling it is a DEF file.

构建DLL时,链接器使用 .def文件以创建导出 (.exp)文件和导入库 (.lib)文件.链接器然后使用 导出文件以构建DLL文件. 隐式链接到的可执行文件 DLL链接到导入库 当他们建立. - MSDN:使用DEF文件从DLL导出

When building the DLL, the linker uses the .def file to create an export (.exp) file and an import library (.lib) file. The linker then uses the export file to build the DLL file. Executables that implicitly link to the DLL link to the import library when they are built. -- MSDN: Exporting from a DLL Using DEF Files

另请参见 MSDN:从DLL(按序号而不是按名称),一起可以回答有关索引或序号导出的最后一个问题.

Also see MSDN: Exporting Functions from a DLL by Ordinal Rather Than by Name, together that should answer your last question on export by index, or ordinal number.

这篇关于链接:.a,.lib和.def文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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