首页未分类 › 如何在64位linux强制编译32位应用程序

如何在64位linux强制编译32位应用程序

方法一:
首先需要安装32位的兼容库
apt-get install ia32-libs libc6-dev-i386 linux32
1.用linux32命令在configure时改一下CHOST,设置一下编译环境
$ linux32 ./configure
#系统类型将变为:i686-pc-linux-gnu
#而不是x86_64-unknown-linux-gnu

2.设定GCC的参数
export CFLAGS=”-m32  -march=i386 -mtune=i386″
export CFLAGS=”-m32 -04 -march=i386 -mtune=i386″
#最关键是-m32
-m32, -m64
Generate code for a 32-bit or 64-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system. The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture.

方法二:
修改/usr/bin/gcc ld,强制加入m32信息
将gcc,ld重命名为gcc.64,ld.64
/usr/bin/gcc
#!/bin/sh
gcc.64 –m32 $@

/usr/bin/ld
#!/bin/sh
ld.64 –m elf_i386 $@

发表评论