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

24 篇文章 0 订阅

原文地址:http://blog.chinaunix.net/uid-20109107-id-86319.html


GDC注:因为需要解决在linux64机上编译32位的mongodb(没办法,因为编译的php是32位,然后我想将mongdb扩展添加到php中),在网上搜了很多文章,感觉这篇好懂,而且好用。我使用的是方法一,具体为:

> linux32 ./configure --with-php-config=/usr/local/php/bin/php-config

> export CFLAGS="-m32 -04 -march=i386 -mtune=i386"

> make

make成功后,用file命令看一下modules目录下的生成的mongo.so。输出为“ELF 32-bit LSB shared object”。哈哈,成功!


方法一:
首先需要安装
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 $@


  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值