Q:

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?
My Makefile link script is 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

A:

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.
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).
This question may be relevant.

