gcc 编译32位程序只需要加参数 -m32即可,如
gcc -m32 hello.c
笔者的系统为:
root@book-virtual-machine:~# cat /proc/version
Linux version 4.13.0-41-generic (buildd@lgw01-amd64-028) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)) #46~16.04.1-Ubuntu SMP Thu May 3 10:06:43 UTC 2018
在编译的时候发生如下错误
/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
参考这里通过如下方案得以解决:
sudo apt-get purge libc6-dev
sudo apt-get install libc6-dev
sudo apt-get install libc6-dev-i386
注:
apt-get 命令中,purge参数会将配置文件一同删除。
libc6 为c库。