windows 将 .a 文件转换为 .dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7851504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert .a file to .dll
提问by Thom
This question is surely answered here somewhere, but I couldn't find it. I've been writing Java for over a decade now and my C experience was on Unix, so I'm kinda at square one here. In my Unix experience, someone else wrote the makefile and it just worked.
这个问题肯定在某处得到了回答,但我找不到。我已经写 Java 十多年了,我的 C 经验是在 Unix 上使用的,所以我在这里有点像。根据我的 Unix 经验,其他人编写了 makefile 并且它可以正常工作。
I have downloaded the C source code for libtar-1.2.11 from feep and ran make
on it from inside of cygwin. This created a .a
file and a .exe
file. The EXE file appears to essentially be tar to run on Windows, but what I wanted was for the libraries to read and process the file in my own code.
我已经从feep 下载了libtar-1.2.11 的C 源代码,并make
从cygwin 内部运行它。这创建了一个.a
文件和一个.exe
文件。EXE 文件似乎本质上是在 Windows 上运行的 tar,但我想要的是让库在我自己的代码中读取和处理文件。
If I remember correctly, those should be in the .a
file (archive??) and this needs to be linked into a library that I can use from my C++ program. So I'm looking for a way to do that.
如果我没记错的话,那些应该在.a
文件中(存档??),这需要链接到我可以从我的 C++ 程序中使用的库中。所以我正在寻找一种方法来做到这一点。
I am writing a library that will use a .tgz
file and so I want to use this library. I think I'd like to turn libtar into a DLL as well as create a DLL myself for use in other languages.
我正在编写一个将使用.tgz
文件的库,所以我想使用这个库。我想我想将 libtar 变成一个 DLL,并自己创建一个 DLL 以用于其他语言。
So, how do I turn my .a
file into something usable by other apps, and how do I access it from inside my code?
那么,如何将我的.a
文件转换为其他应用程序可用的文件,以及如何从我的代码内部访问它?
回答by aayoubi
The generated libmylib.a
is actually an archive of all *.o
for libtar-1.2.11
.
you can verify this by doing nm libmylib.a
, it will print all the *.o
files.
Write your code, and link:
生成libmylib.a
的实际上是所有*.o
for的存档libtar-1.2.11
。
您可以通过这样做来验证这一点nm libmylib.a
,它将打印所有*.o
文件。
编写您的代码,并链接:
gcc -o my_application my_application.o -lmylib
You generated this with cygwin, you can't generate a dll out of that as far as i know.
你用cygwin生成了这个,据我所知,你不能从中生成一个dll。
回答by themel
Well, a DLL is the equivalent of a sharedlibrary in Unix (a .a
is a library for static linking, the Windows equivalent being a .LIB
file), so you want to build a shared library.
嗯,DLL 相当于Unix中的共享库(a.a
是用于静态链接的库,Windows 相当于是一个.LIB
文件),因此您想要构建一个共享库。
Indeed, when you build as
事实上,当你构建为
make LDFLAGS=-shared
make LDFLAGS=-shared
the resulting libtar/libtar.exe
will actually be a misnamed DLL.
结果libtar/libtar.exe
实际上是一个错误命名的 DLL。
Note, however, that a cygwin-translated DLL is something different from a native Windows DLL and will always depend on Cygwin DLLs (and potentially even an installed Cygwin environment) to run, so if you plan on including it in native Windows code, this is probably not an approach you want to pursue.
但是请注意,cygwin 转换的 DLL 与本机 Windows DLL 有所不同,并且将始终依赖于 Cygwin DLL(甚至可能是已安装的 Cygwin 环境)才能运行,因此如果您计划将其包含在本机 Windows 代码中,这可能不是您想要追求的方法。
May I suggest that you switch from the plenty dead (last release in 2003) libtar to libarchive, which comes with native Windows build instructions?
我可以建议您从大量已死的(2003 年最后一次发布)libtar 切换到带有本地Windows 构建说明的libarchive吗?