64位linux 编译c提示gnu/stubs-32.h:No such file or directory的解决方法

2020-03-22 18:00:53于丽

使用了-m2的参数就会链接到32位版本的编译器,修改所有的Makefile文件,查看
是否有什么32位编译的删除即可。

查阅的外文资料几乎没有任何用处:
On Ubuntu it's called libc6-dev-i386 - do sudo apt-get install libc6-dev-i386. See below for extra instructions for Ubuntu 12.04.

On Red Hat distros, the package name is glibc-devel.i686 (Thanks to David Gardner's comment)

On CentOS 5.8, the package name is glibc-devel.i386 (Thanks to JimKleck's comment)

On CentOS 6.3, the package name is glibc-devel.i686.

On SLES it's called glibc-devel-32bit - do zypper in glibc-devel-32bit
在SLES系统上,执行上述指令安装,在/usr/include/gnu目录下确实生成了上述的文件。
在CentOS系统上,无效。

64位的机器上找不到32位的头文件。所以要安装glibc-devel.i686(redhat不同系统不太一样)

随手搜了一个rpm包,用rpm -ivh安装报错:(因为服务器不联外网,所以这么安装)

error:Failed dependencies

忽略依赖关系问题
rpm –nodeps -i 即可安装成功

cd /usr/include/gnu/下查看,文件stubs-32.h已经存在。解决问题。

下面是/usr/include/gnu/stubs.h文件的内容如下:

/* This file selects the right generated file of `__stub_FUNCTION' macros
based on the architecture being compiled for. */

include
if __WORDSIZE == 32
include
elif __WORDSIZE == 64
include
els
error “unexpected value for __WORDSIZE macro”
endif
~

其实就是根据__WORDSIZE的值来决定使用32位的头文件还是64位的头文件。