64位linux 編譯c提示gnu/stubs-32.h:No such file or directory的解決方法
64位linux提示gnu/stubs-32.h:No such file or directory的解決方法
這個問題是由于缺少32位兼容包,解決辦法:
ubuntu: sudo apt-get install libc6-dev-i386
CentOS:yum -y install glibc-devel.i686
Re阿里云yum源沒有g(shù)libc.i686
阿里云的64位Linux發(fā)行版屏蔽了32位,也就是常見的i686軟件包的數(shù)據(jù)源,你可以修改yum的配置文件/etc/yum.conf,找到其中exclude=*.i?86 kernel kernel-xen kernel-debug,用#注釋掉即可,但是阿里不贊成這么做,如果32位、64位混用,比較容易出問題。
今天在64位linux編譯程序時,出現(xiàn)如下錯誤提示
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h:No such file or directory
解決方法如下
# yum -y install glibc-devel
場景描述:在編譯程序的時候出現(xiàn)如下的錯誤:
make[1]: Entering directory `/root/rpmbuild/BUILD/test/conf'
In file included from /usr/include/features.h:385,
from /usr/include/stdint.h:26,
from ../include/MyTypes.h:4,
from conf_init.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
make[1]: *** [conf_init32.o] Error 1
make[1]: Leaving directory `/root/rpmbuild/BUILD/test/conf'
make: *** [all] Error 1
解決過程:
1完全無法分析天書般的錯誤,英文非常簡單,但是翻譯非常困難,好在
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
這一句了解,好既然少這個文件,拷貝一個文件過來,OK解決問題。
2.經(jīng)過老大的解決思路,看出端倪。
說明如下:conf_init.c:第一行引用../include/MyTypes.h頭文件,
而這個頭文件在第四行引用/usr/include/stdint.h頭文件,
而這個頭文件在第26行引用/usr/include/features.h頭文件,
而這個頭文件在第385行應(yīng)用了/usr/include/gnu/stubs.h頭文件,
而這個頭文件在第7行引用了gnu/stubs-32.h頭文件
然后在編譯的過程中,沒有發(fā)現(xiàn)這個文件。大體意思清楚沒有。
下面是/usr/include/gnu/stubs.h文件的內(nèi)容如下:
/* This file selects the right generated file of `__stub_FUNCTION' macros based on the architecture being compiled for. */ #include <bits/wordsize.h> #if __WORDSIZE == 32 # include <gnu/stubs-32.h> #elif __WORDSIZE == 64 # include <gnu/stubs-64.h> #els # error "unexpected value for __WORDSIZE macro" #endif ~
注明:這個文件說明了64位或者32位編譯環(huán)境選擇的頭文件。所以在編譯的過程中,
使用了-m2的參數(shù)就會鏈接到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系統(tǒng)上,執(zhí)行上述指令安裝,在/usr/include/gnu目錄下確實(shí)生成了上述的文件。
在CentOS系統(tǒng)上,無效。
64位的機(jī)器上找不到32位的頭文件。所以要安裝glibc-devel.i686(redhat不同系統(tǒng)不太一樣)
隨手搜了一個rpm包,用rpm -ivh安裝報錯:(因?yàn)榉?wù)器不聯(lián)外網(wǎng),所以這么安裝)
error:Failed dependencies
忽略依賴關(guān)系問題
rpm –nodeps -i
即可安裝成功
cd /usr/include/gnu/下查看,文件stubs-32.h已經(jīng)存在。解決問題。
下面是/usr/include/gnu/stubs.h文件的內(nèi)容如下:
/* 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
~
其實(shí)就是根據(jù)__WORDSIZE的值來決定使用32位的頭文件還是64位的頭文件。
相關(guān)文章
Windows 環(huán)境下使用 Qt 連接 MySQL
這篇文章主要介紹了Windows 環(huán)境下使用 Qt 連接 MySQL的相關(guān)資料,需要的朋友可以參考下2017-07-07C語言實(shí)現(xiàn)strlen的三種方法小結(jié)
本文主要介紹了C語言實(shí)現(xiàn)strlen的三種方法小結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06C++入門基礎(chǔ)之命名空間、輸入輸出和缺省參數(shù)
C++入門基礎(chǔ)篇的內(nèi)容為C++的基本特性,只有在掌握C++的基本特性后,是進(jìn)入后面類和對象學(xué)習(xí)的基礎(chǔ),下面這篇文章主要給大家介紹了關(guān)于C++入門基礎(chǔ)之命名空間、輸入輸出和缺省參數(shù)的相關(guān)資料,需要的朋友可以參考下2023-01-01