环境
- 基于debian的uos系统
- mips 架构
- 64 bit系统
安装gcc-multilib
sudo apt install gcc-multilib 如果不安装这个包将会报错:
$ gcc 1.c -mabi=32
In file included from 1.c:4:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: 没有那个文件或目录
^~~~~~~~~~~~~~~~~~~~~~~~~~
编译32为程序需要添加的gcc 选项
架构 | gcc选项 |
---|
alpha | impossible? | amd64 | -m32 | arm64 | -mabi=ilp32 | ia64 | -milp32 | mips64el | -mabi=32 | ppc64 | -m32 | ppc64el | -m32 | s390x | -m31 | sparc64 | -m32 |
示例
$ echo 'main(){}' | gcc -x c -o test -
$ file test
test: ELF 64-bit LSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked, interpreter /lib64/ld.so.1, BuildID[sha1]=eb7499a0bf2e6bed2a1e26f5e399b1d2d02b0ced, for GNU/Linux 3.2.0, not stripped
gcc加上-mabi=32选项
$ echo 'main(){}' | gcc -x c -o test - -mabi=32
$ file test
test: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, BuildID[sha1]=ec1fc4cefa462dcdd5468207422b5a41ed749831, not stripped
|