#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
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
看 /usr/lib 目录有没有 libc.a
或
c只能 动态 静态 而且 运行 本地必须有标准库
拷贝libc.a到当前目录
gcc main.c -L. -lc