在链接描述文件中提取存档文件 [英] Extracting archive file in linker script
问题描述
我正在尝试解决以下问题:
I am trying to deal with a problem like the following one:
假设我有一个库libxyz.a,创建自:
Assume that I have a library libxyz.a created from:
/* main.c */
int main(void)
{
int a;
}
使用以下文件进行编译和存档:
compiled and archived with:
gcc -c main.c -o abc.o && ar cr libxyz.a abc.o
我必须如何编写链接程序脚本才能将abc.o准确放置在预期位置?
How do I have to write linker script in order to put abc.o exactly where it is expected to be?
我试图以这种方式处理它:
I was trying to handle it in such way:
/* script.ld */
SEARCH_DIR(.)
INPUT(-lxyz)
SECTIONS
{
.text : { xyz:abc(.text) }
.data : { xyz:abc(.data) }
.bss : { xyz:abc(.bss) }
}
但运行后:
ld -T script.ld
我得到:
ld: cannot find xyz:abc
我在论坛的链接器文件中找不到提取存档的任何示例.我唯一发现的是链接器的文档,该文档仅包含有关 archive:file
构造的信息.
I couldn't find any example of extracting archives in linker files on forums. The only thing I have found was the linker's documentation, which only contains information about archive:file
construction.
推荐答案
今天只需要处理相同的问题,因此如果有人碰到这个问题:缺少某些文件扩展名.像这样的东西很好:
Just had to deal with same problem today, so if someone else bumps into this question: some file extensions are missing. Something like works fine:
SECTIONS
{
.text : { libxyz.a:abc.o(.text) }
.data : { libxyz.a:abc.o(.data) }
.bss : { libxyz.a:abc.o(.bss) }
}
还需要处理路径(如果库实际上在/libxyz.a中).
One also needs to deal with paths (if library is actually somewhere/libxyz.a).
这篇关于在链接描述文件中提取存档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!