背景
在64位系统上编译32位可执行程序时出现报错,
[root@CentOS-7-2 /home/register]# gcc -g -m32 test.c -o test
In file included from /usr/include/features.h:399:0,
from /usr/include/stdio.h:27,
from test.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
# include <gnu/stubs-32.h>
^
compilation terminated.
解决方案
缺少头文件,使用yum provides命令查询哪个组件可以提供该头文件即可,
[root@CentOS-7-2 /home/register]# yum provides */stubs-32.h
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: fedora.cs.nctu.edu.tw
* epel-source: fedora.cs.nctu.edu.tw
glibc-devel-2.17-260.el7.i686 : Object files for development using standard C libraries.
Repo : base
Matched from:
Filename : /usr/include/gnu/stubs-32.h
可见,安装glibc-devel组件即可。但是要注意的是,因为是在64位机器上,因此如果执行以下命令来安装,
yum install -y glibc-devel
最终安装的是x86_64架构的组件,因此需要制定组件全名,
yum install -y glibc-devel-2.17-260.el7.i686
安装结束后,编译OK,
[root@CentOS-7-2 /home/register]# gcc -g -m32 test.c -o test
[root@CentOS-7-2 /home/register]# ls
. .. test test.c
[root@CentOS-7-2 /home/register]# file test
test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=9fe99fd19a1bcc8602013ce4cd14ad08c12df6a9, not stripped