We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
我不知道有什么,但你可以自己实现一个。只需使用 nm 从每个静态库获取符号列表,使用它构建依赖关系图,然后对图执行拓扑排序以获得正确的链接顺序。
或者,使用部分链接 (
ld -r
) 而不是静态库。由于这会输出合并的 .o 文件,因此您的最终链接可以按任何顺序声明库,并且它们都将正确链接。缺点是链接器无法丢弃未使用的源文件,因为在使用数据可用之前它们已经链接到整体文件中(您可以通过传递-ffunction-sections -fdata-sections< /code> 在编译期间和
-Wl,--gc-sections
在最终链接上,尽管这可能会影响编译所需的时间)I'm not aware of one offhand, but you could implement one yourself. Just use
nm
to get a list of symbols from each static library, use this to build a dependency graph, then perform a topological sort over the graph for the proper link order.Alternately, use partial links (
ld -r
) instead of static libraries. Since this outputs a merged .o file, your final link can declare the libraries in any order, and they'll all be linked properly. The downside is that the linker won't be able to discard unused source files, since they're already linked into monolithic files before usage data is available (you can workaround this by passing-ffunction-sections -fdata-sections
during compilation and-Wl,--gc-sections
on final link, although this may impact how long it takes to compile)您可以使用共享库而不是静态库,并使用
-fPIC
选项进行编译。You could use shared libraries instead of static and compile with
-fPIC
option.