结合静态库 [英] Combining static libraries

查看:137
本文介绍了结合静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有三个 C 静态库说的 libColor.a 的依赖于* libRGB *一这又依赖于的 libPixel.a 。该库的 libColor.a 的据说是依赖于图书馆的 libRGB.a 的,因为有一些定义符号的的 libColor.a 的一些参考的 libRGB.a 的。怎样所有上述库结合到一个新的 libNewColor.a 的是独立?

Suppose I have three C static libraries say libColor.a which depends on *libRGB.*a which in turn depends on libPixel.a . The library libColor.a is said to depend on library libRGB.a since there are some references in libColor.a to some of symbols defined in libRGB.a. How do I combine all the above libraries to a new libNewColor.a which is independent?

独立意味着新的库应该有定义的所有符号。因此,尽管联我只是需要给 -lNewColor 。新库的大小应该是最小的即它不应该包含未使用的 libColor.a 的等在的 libRGB.a 的任何符号
我用各种选项尝试我的运气 AR 命令(用于创建和更新静态库/存档)。

Independent means the new library should have all symbols defined. So while linking I just need to give -lNewColor. The size of the new library should be minimal i.e it should not contain any symbols in libRGB.a which is not used by libColor.a etc. I tried my luck using various options in ar command (used to create and update static libraries/archives).

推荐答案

1 /提取所有从每个库中的目标文件(使用 AR ),并尝试编译code,而不库或目标文件。你可能会得到未定义符号的绝对斗负荷。如果你没有未定义的符号,则转到步骤5。

1/ Extract ALL of the object files from each library (using ar) and try to compile your code without the libraries or any of the object files. You'll probably get an absolute bucket-load of undefined symbols. If you get no undefined symbols, go to step 5.

2 /抓斗的第一个,并找出哪些对象文件满足该符号(使用纳米)。

2/ Grab the first one and find out which object file satisfies that symbol (using nm).

3 /写下目标文件,然后编译code,包括新的目标文件。你会得到未定义符号的一个新的列表,或者,如果有没有,请转到步骤5。

3/ Write down that object file then compile your code, including the new object file. You'll get a new list of undefined symbols or, if there's none, go to step 5.

4 /转到步骤2。

5 /将所有的目标文件在列表中(如果有的话)到一个库中(以再次AR )。

5/ Combine all the object files in your list (if any) into a single library (again with ar).

砰!有你有它。尝试不使用任何对象的链接您的code,但的新库。

Bang! There you have it. Try to link your code without any of the objects but with the new library.

这整个事情可以相对容易地与一个shell脚本的自动化。

This whole thing could be relatively easily automated with a shell script.

这篇关于结合静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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