UNIX:链接到静态库的静态库
可能的重复:
如何打包多个库存档 (.a)到一个存档文件中?
我遇到一种情况,我必须仅向可执行文件提供一个静态库(.a 文件)来构建它。
但是,我将此库分为两部分,因为一部分是其他可执行文件所共用的,另一部分只有一个可执行文件需要。
所以现在我有lib1(对于exe1)和lib2(对于所有exe)
问题是我无法提供两个库,所以我必须将exe1,lib2合并到lib1中
我尝试使用-llib2编译lib1.o但是即使有效,看起来就像什么也没发生一样
还有其他方法吗?我只能考虑使用原始对象文件,但我不喜欢这个想法
Possible Duplicate:
How to pack multiple library archives (.a) into one archive file?
I have a situation where I must provide only a single static library (.a file) to an executable file to build it.
However, I split this lib in 2 parts because one part is common to other executable files and the other is needed only by one.
So now I have lib1 (for exe1) and lib2 (for all exes)
The problem is that I can't provide two libs, so I must merge for exe1, lib2 into lib1
I tried my compiling the lib1.o with -llib2 but even if it works, it looks like if nothing happened
Are there any other way? I'm can only think about using raw object files but I don't like this idea
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要两个静态库;当使用静态库时,仅将需要的函数(或变量)复制到可执行文件 - 与共享库不同,在共享库中,可执行文件可以访问库中的所有内容。
从机械上讲,引用的另一个问题描述了您需要执行的操作:
或者:
There's no need for two static libraries; when a static library is used, only the functions (or variables) that are needed are copied to the executable - unlike a shared library where everything in the library is accessible to the executable.
Mechanically, the other question referenced describes what you need to do:
Or:
您甚至可以编译每个源文件,生成所有 .o 并使用 ar 创建两个不同的库。
整个库将使用所有 .o(您将 lib1.a 和 lib2.a 一起放入的库)生成,较小的库将仅使用一组减少的 .o 文件。
比...单个 Makefile、生成一次的 .o 文件、从这项工作中得出的两个库:完整的库(libaplus2.a)和简化的库(lib1.a)。
You can even compile each source file, produce all .o and create two different libs by using ar.
The whole library will be produced using all .o (the ones you put in lib1.a and lib2.a together), the smaller one will use just a reduced set of .o files.
Than... a single Makefile, .o files produced once, two libraryes coming out from this job: the complete one (libaplus2.a) and the reduced one (lib1.a).