存档中嵌入的动态链接程序依赖项信息 [英] dynamic linker dependency info embedded in an archive

查看:67
本文介绍了存档中嵌入的动态链接程序依赖项信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态库很不错.它们中包含的嵌入式信息可帮助运行时链接程序确定最终可执行文件还需要加载哪些其他库.它还告诉可执行文件将加载什么符号

Dynamic libraries are nice. The have embedded information in them that help the runtime linker figure what other libraries the final executable needs to load. It also tells the executable what symbols will be loaded

但是,静态库却让人头疼.链接器不会自动链接存档的依赖项.当静态链接一个复杂程度较高或具有较深依赖关系图的库时,这会令人发指.

Static libraries, however, are a pain in the neck. The linker won't automatically link an archive's dependencies. This get heinous when statically linking a library that is moderately complicated or has a deep dependency graph.

那么为什么存档不能仅包含其依赖项信息?我试图做到这一点.我的想法的关键是/usr/lib/libc.so.此文件不是共享库文件,而是链接描述文件.

So why can't archives just include their dependency information? I tried to do just that. The key to my idea is /usr/lib/libc.so. This file is not a shared object file but a linker script.

链接器脚本为您提供了对最终链接器输出的很多控制,但是我要做的就是指定可​​以使用的依赖项:

Linker scripts give you a lot of control over the final linker output, but all I want is to specify dependencies which you can with:

INPUT( -ldependency -ldependecy2 )

这是我的问题.

  • 这似乎很简单,为什么以前没有做过呢?我不能成为第一个想到这个的人.与pkg-config或libtool(尤其是libtool ugh)相比,这似乎更容易,更直观.
  • 我试图将链接描述文件嵌入存档中,但它不起作用.为什么不?可以使它工作吗?我怀疑巧妙地使用ranlib可以解决问题,但这超出了我的范围.

我当前的解决方案是创建一个名为libMyLibrary.a的链接脚本.它包含

My current solution is create a linker script called libMyLibrary.a. It contains

INPUT( -lMyRealLibrary -ldependency1 -ldependency2 )

我必须手动输入依赖项,如果ld对我来说会很好,但这又是一天的问题.

I have to put in the dependencies by hand, it would be nice if ld could for me, but that is problem for another day.

推荐答案

要回答问题的第二部分,ar p ARCHIVE SCRIPT将列出ARCHIVE中包含的SCRIPT的内容.或ar x ARCHIVE SCRIPT提取文件,然后将其传递给链接器,如ld blah blah -TSCRIPT.

To answer the second part of your question, ar p ARCHIVE SCRIPT will cat the contents of SCRIPT contained in ARCHIVE. Or ar x ARCHIVE SCRIPT to extract the file and then pass it to the linker like ld blah blah -TSCRIPT.

这篇关于存档中嵌入的动态链接程序依赖项信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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