#include<stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
a.out main.c
$ gcc -static main.c
[localhost test]$ gcc -static main.c
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
$ gcc main.c
$ ls
test]$ ldd a.out
linux-vdso.so.1 => (0x00007fff0c3fe000)
libc.so.6 => /lib64/libc.so.6 (0x00007f5cbb43a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5cbb802000)
[root@ctos helloworld]# gcc -static hello.c
[root@ctos helloworld]# ls
a.out hello hello.c hello.go mv
[root@ctos helloworld]# ldd a.out
not a dynamic executable
[localhost test]$ gcc -static main.c
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
阿神2017-04-17 13:49:14
Check if there is libc.a in the /usr/lib directory
$ gcc -static main.c
or
$ gcc -static -lc main.c
PHP中文网2017-04-17 13:49:14
c can only be dynamic or static and running locally must have a standard library