欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory

程序员文章站 2022-07-15 16:52:26
...

背景

在64位系统上编译32位可执行程序时出现报错,

[[email protected] /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命令查询哪个组件可以提供该头文件即可,

[[email protected] /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,

[[email protected] /home/register]# gcc -g -m32 test.c -o test
[[email protected] /home/register]# ls
.  ..  test  test.c
[[email protected] /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