ld: link with std c 静态库

ld: link with std c static library

我用 gcc -c -nostdlib -fno-stack-protector <my code> -o <my cobj> 编译我的 c 代码,我想使用 std 库函数,如 sprintf strcmp 等 on.So 怎么能我 link 我的 cobj 文件有 std c 静态库?

我的Makefilelink脚本是ld -T $@.ld -o $@.o $^ -L.. -llib --no-check-sections

ps:我使用 -nostdlib 选项编译,因为我不想要 std 库的 crt 部分,但我想使用平台- sprintfstrcmprandomva_list等独立函数

您可以使用 -nostartfiles -static -nostdlib -fno-stack-protector -lc 进行编译,但请注意 libc 的某些部分可能依赖于 libgcc(__gcc_personality_v0 等)的部分,因此您很可能在链接过程中出错。

您可以提供您自己的此类函数的虚拟(或不那么虚拟)实现。或者您可以使用不依赖于 libgcc 的不同 libc 实现(可能是 newlib 或 uClibc)。

This question 可能相关。