【发布时间】:2013-01-03 07:17:22
【问题描述】:
考虑 hello world C 程序:
hello.c:
#include "stdio.h"
int main()
{
printf("Hello, World!\n");
}
如果我打电话:
$ gcc -c hello.c -o hello.o
它将生成一个 ELF 可重定位文件 hello.o
如果我再打电话:
$ gcc hello.o -o hello [1]
它将 hello.o 与 ld 链接并生成一个 ELF 可执行文件 hello
但是,如果我直接调用 ld [2] 而不是 [1]:
$ ld hello.o -o hello [2]
我收到以下错误:
/usr/bin/ld.bfd.real: warning: cannot find entry symbol _start
test.c:(.text+0xa): undefined reference to `puts'
gcc 必须将其他选项传递给 ld(例如链接 C 库)。
有没有办法确定命令行 gcc 在命令 [1] 中传递给 ld 的确切内容?
【问题讨论】: