静态链接与交叉编译器

时间:2013-06-16 18:30:55

标签: static linker

我的test.c程序使用printf函数。我想静态链接我需要的库。我使用arm-linux-gnueabi-gcc交叉编译器。

当我像这样编译我的代码时

arm-linux-gnueabi-gcc test.c -o test

它通过了,但我认为他仍然通过查看测试的解集来使用动态链接。

那么,为了静态链接libc.a库,我应该添加什么选项?

1 个答案:

答案 0 :(得分:2)

尝试

arm-linux-gnueabi-gcc test.c -o test -Xlinker -static /path/to/libc.a

这对我有用。此外,它可能会抱怨您没有静态libgcc_s。然后试试这个:

arm-linux-gnueabi-gcc test.c -o test -Xlinker -static /path/to/libc.a -static-libgcc

希望这有帮助!