Problem with static compiling - GCC

Hi guys.

I want to compile three files:

gcc -static main.c fib.c fib.h

it is pure C i mean i use standard C library.
but it gives me this error:

/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status

what should i do?

You probably don't have a static version of your c library installed - confirm by running "whereis libc" (it should show a libc.so, but no libc.a) and search your package manager for "libc.a", "gcc static" or "libc static" for something to install.

1 Like

It'd help to know the OS, too.

Thank you very much. I found the package. it's name is:

glibc-static

Try:

gcc -static -o fib main.c fib.c fib.h

This will compile an executable "fib"..I assume a Fibonacci example..statically.