[英]ld: link with std c static library
I compile my c code with gcc -c -nostdlib -fno-stack-protector <my code> -o <my cobj>
, and I want to use the std
library functions like sprintf
strcmp
and so on.So how can I link my cobj
files with std
c
static library? 我用gcc -c -nostdlib -fno-stack-protector <my code> -o <my cobj>
编译我的c代码,我想使用sprintf
strcmp
类的std
库函数,所以该如何链接我的具有std
c
静态库的cobj
文件?
My Makefile
link script is ld -T $@.ld -o $@.o $^ -L.. -llib --no-check-sections
我的Makefile
链接脚本是ld -T $@.ld -o $@.o $^ -L.. -llib --no-check-sections
ps: I compile with -nostdlib
option because I don't want the crt
part of the std
library, but I want to use the platform-independent functions like sprintf
, strcmp
, random
, va_list
and so on ps:我使用-nostdlib
选项进行编译,因为我不想使用std
库的crt
部分,但是我想使用平台无关的函数,例如sprintf
, strcmp
, random
, va_list
等
You can compile with -nostartfiles -static -nostdlib -fno-stack-protector -lc
but beware that some parts of libc may have dependencies on pieces from libgcc ( __gcc_personality_v0
, etc.) so you'll most probably have errors during linking. 您可以使用-nostartfiles -static -nostdlib -fno-stack-protector -lc
进行编译,但请注意,libc的某些部分可能依赖于libgcc的片段( __gcc_personality_v0
等),因此链接期间很可能会出错。
You can provide your own dummy (or not so dummy) implementations of such functions. 您可以提供此类功能的伪(或非伪)实现。 Or you could just use different libc implementation which does not depend on libgcc (probably newlib or uClibc). 或者,您可以使用不依赖libgcc的其他libc实现(可能是newlib或uClibc)。
This question may be relevant. 这个问题可能是相关的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.