<摘錄>如何在64位linux強制編譯32位應用程序


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 $@


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM