这个问题肯定在某个地方有答案,但我找不到。我编写 Java 已经有十多年了,而我的 C 经验是在 Unix 上的,所以我在这里还处于起步阶段。根据我的 Unix 经验,其他人编写了 makefile,它就可以工作。
我已经从feep下载了libtar-1.2.11的C源代码,并从cygwin内部运行了make
。这创建了一个 .a
文件和一个 .exe
文件。 EXE 文件本质上似乎是在 Windows 上运行的 tar,但我想要的是让库在我自己的代码中读取和处理该文件。
如果我没记错的话,这些应该位于 .a
文件(存档??)中,并且需要将其链接到我可以从我的 C++ 程序中使用的库中。所以我正在寻找一种方法来做到这一点。
我正在编写一个将使用 .tgz
文件的库,因此我想使用这个库。我想我想将 libtar 转换为 DLL 并自己创建一个 DLL 以在其他语言中使用。
那么,如何将我的 .a
文件转换为其他应用程序可以使用的文件,以及如何从代码内部访问它?
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.
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.
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.
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.
So, how do I turn my .a
file into something usable by other apps, and how do I access it from inside my code?
发布评论
评论(2)
生成的
libmylib.a
实际上是libtar-1.2.11
的所有*.o
的存档。您可以通过执行
nm libmylib.a
来验证这一点,它将打印所有*.o
文件。编写你的代码,并链接:
你用 cygwin 生成了这个,据我所知,你不能从中生成 dll。
The generated
libmylib.a
is actually an archive of all*.o
forlibtar-1.2.11
.you can verify this by doing
nm libmylib.a
, it will print all the*.o
files.Write your code, and link:
You generated this with cygwin, you can't generate a dll out of that as far as i know.
好吧,DLL 相当于 Unix 中的共享库(
.a
是静态链接库,Windows 相当于.LIB code> file),所以你想构建一个共享库。
事实上,当您构建为
make LDFLAGS=-shared
时,生成的
libtar/libtar.exe
实际上将是一个错误命名的 DLL。但请注意,cygwin 翻译的 DLL 与本机 Windows DLL 不同,并且始终依赖于 Cygwin DLL(甚至可能依赖于已安装的 Cygwin 环境)来运行,因此,如果您计划将其包含在本机 Windows 代码中,则此可能不是您想要追求的方法。
我可以建议你从已经死了的(最后一个版本是 2003 年)libtar 切换到 libarchive,它带有本机 Windows 构建说明?
Well, a DLL is the equivalent of a shared library 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.Indeed, when you build as
make LDFLAGS=-shared
the resulting
libtar/libtar.exe
will actually be a misnamed 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.
May I suggest that you switch from the plenty dead (last release in 2003) libtar to libarchive, which comes with native Windows build instructions?