When I try to compile static, I am getting the following error:
gcc defrag.c -o abc.exe --static
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
However, the same thing compiles fine without static:
gcc defrag.c -o abc.exe
Question: Why did the compilation failed when static is specified?
The error is occurring becuase “–static” says that all subsequent libraries in your link command must be static … but you only have a dynamic libc on your system.
Recommended solution:
gcc defrag.c -o abc -lc –static -lmystaticlib
If you’re just trying to create a static exe for the sake of having a static exe – I’d recommend “don’t”. Shared libraries are Good. For many different reasons.
Here’s a good link: