在另一个库(SDL 和 Eclipse)之上构建新库
我正在与 SDL 合作开展一个项目。我觉得我的很多代码可以/应该可重用于我可能想要承担的任何其他项目。
我打算启动一个库项目,但我不知道如何链接到 SDL 库。
通常,我会转到“项目设置”并编辑 Mingw32 Linker 以包含库(ming32、SDLmain 和 SDL)。但链接器没有显示在设置中。
所以我的问题是:
是否没有链接器设置,因为构建库只是一个编译操作?
一般来说,是否可以在现有库的基础上构建一个库?也就是说,使用 SDL 函数和结构编写我的库。或者我是否必须获取源代码并完全重建包含我的代码?
另外,在这种情况下,关于共享与静态的建议?
(另外,关于在哪里进一步了解编译器和链接器等的任何建议。我在学校学习了数据结构,但没有进一步学习)
I am working on a project with SDL. I feel like a lot of my code could/should be reusable for any other projects I might want to take on.
I was going to start a library project, but I don't know how to go about linking to the SDL libraries.
Usually, I go to Project Settings and edited Mingw32 Linker to include the libraries (ming32, SDLmain, and SDL). But the linker does not show up in the settings.
So my questions:
Is there no linker settings because building a library is only a compiling operation?
And in general, is it possible to build a library on top of the existing libraries? That is, write my library using SDL functions and stucts. Or would I have to get the source code and rebuild entirely with my code included?
Also, advice on shared vs. static in this instance?
(Also, any advice for where to go about learning more about compilers and linkers and such. I got through data structures in school but no farther)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为介绍,您必须很好地区分静态库和动态库,它们是完全不同的野兽......对您的问题说:
我猜你在这种情况下正在创建一个静态库。静态库只是构成源树的所有单个对象文件(即编译器生成的
.o
文件)在一个对象文件中的集合。不多也不少。使用静态库,您不需要指定哪些依赖项,因为可以理解,在编译最终的可执行文件时,您的库将与其依赖的所有其他库链接。因此,只有在那时(最终可执行版本)才会检测到任何丢失的符号,并且所有其他库都必须可用。
共享库(也称为动态库)是一个嵌入了它所依赖的所有静态库的可执行文件。它还可以与其他共享库具有外部依赖关系,而这些共享库不会被嵌入。
对于静态库和动态库来说,这是完全可能的。
在这种情况下,无法提供建议,因为您没有指定足够的信息。
看看这个:何时使用动态库与静态库,以及这个,有一种指导方针。
(另外,关于在哪里进一步了解编译器和链接器等的任何建议。我在学校学习过数据结构,但仅此而已)
我认为上面的两个链接为您提供了大量信息。如果您想进一步了解详细信息,可以从这篇维基百科文章开始并从那里浏览。
As an introduction, you have to distinguish very well static library from dynamic ones, they are completely different beasts... said that, to your questions:
I guess you are creating a static library in this case. A static library is simply the collection in one single object file of all the individual object files (i.e., the
.o
files produced by the compiler) that make up your source tree. No more, no less.With a static library you don't need to specify which are the dependencies, since it is understood that it is when compiling the final executable that your library will be linked with all the other libraries that it depends upon. Therefore it is only at that time (final executable build) that any missing symbol will be detected, and all other libraries must be available.
A shared library (also dynamic library), is an executable file that embeds all the static libraries that it depends upon. It can also have external dependencies with other shared library, which would not be embedded.
It is perfectly possible, both for static and dynamic libraries.
In this instance it is not possible to advice, because you don't specify enough information.
Look at this: When to use dynamic vs. static libraries, and this, to have a sort of guideline.
(Also, any advice for where to go about learning more about compilers and linkers and such. I got through data structures in school but no farther)
I think that the two links above give you plenty of information. If you want to further go into details, you could start from this wikipedia article and browse from there.
您正在构建的库可以具有外部依赖项。这意味着您可以将其与 SDL 或您喜欢的任何其他外部库链接。
我认为此页面解释了您所有其他问题:DLL Creation in MingW
The library you are building can have external dependencies. That means that you can link it with SDL or any other external libraries that you like.
I think this page explains all your other questions: DLL Creation in MingW