ubuntu 64上的GCC如何编译32位程序
运行命令
gcc -v
显示:
Target: x86_64-linux-gnu
所以,我这里的 gcc 默认生成 64 位的程序。
如果想编出 32 位的程序,就要加 -m32 选项。
同时确保系统安装如下库
sudo apt-get install build-essential module-assistant
sudo apt-get install gcc-multilib g++-multilib
装好之后,就 OK 了。
比如:
gcc -m32 hello.c
使用 file 查看编译后文件位数
root@55ce0fbe4b63:demo# file csondemo
csondemo: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked