gcc编译报错: /usr/bin/ld: cannot find -lc

背景

在64位机器上编译32位可执行程序,出现以下报错,

[root@CentOS-7-4 /home/syscall]# gcc -g -static -m32 open.c -o open32
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

解决方案

这其实是因为缺少32位相关编译环境,需要安装glibc-static组件,

yum install -y glibc-static.i686

安装后,编译正常,

[root@CentOS-7-4 /home/syscall]# gcc -g -static -m32 open.c -o open32
[root@CentOS-7-4 /home/syscall]# ls
.  ..  open32  open.c 
[root@CentOS-7-4 /home/syscall]# file open32
open32: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=6f5591d9ad182e332149c6f2380db9dade351d26, not stripped

你可能感兴趣的:(Linux,cannot,find,-lc,glibc-static)