GCC静态编译32位程序

转【 http://www.dengdeng.name/u/deng/archives/2010/88.html】
GCC静态编译32位程序
     编译指令:gcc  -o init hello.c -static -m32
     -static 静态编译
    -m32  32位可执行文件(64位系统默认编译结果是64位)
出现错误提示:
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
是缺少glibc-static.i686
yum 安装之(为了编译64时不出此错误,把glibc-static.x86_64也装上),再编译,出现:
In file included from /usr/include/features.h:385,
                 from /usr/include/stdio.h:28,
                 from hello.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory

因缺少
glibc-devel.i686
再安装,编译,一切大功告成

你可能感兴趣的:(GCC静态编译32位程序)