Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1660934
  • 博文数量: 391
  • 博客积分: 8464
  • 博客等级: 中将
  • 技术积分: 4589
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-13 15:12
个人简介

狮子的雄心,骆驼的耐力,孩子的执著!

文章分类

全部博文(391)

文章存档

2023年(4)

2018年(9)

2017年(13)

2016年(18)

2014年(7)

2013年(29)

2012年(61)

2011年(49)

2010年(84)

2009年(95)

2008年(22)

分类: C/C++

2010-08-09 09:24:02

测试环境:
CPU : 64bit Intel(R) Xeon(TM) CPU 2.80GHz * 2
OS :Debain / Linux 2.6.17.11 #2 SMP Thu Sep 7 00:44:27 CST 2006 x86_64 GNU/Linux
GCC: version 4.1.2 20060814 (prerelease) (Debian 4.1.1-11)

背景知识:

我们的 64bit Debain 需要安装以下软件包

apt-get install ia32-libs libc6-dev-i386 linux32

1) 最关键的东西是需要告知gcc编译器编译的平台是 i386,CFLAGS 必须添加 -m32 参数. []

2) 用 linux32 命令在configure改一下CHOST,设置一下编译环境

linux32 命令使用前后区别

staff-1:~/src/lame-3.96.1# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu

staff-1:~/src/lame-3.96.1# linux32 ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu

3) 如果编译的程序是32位的,所需要的动态链接库也需重新编译,例如mplayer需要用到 mp3lame,jpeg-6b,libpng等,均需要重新编译.

4) 如何知道应用程序是64位还是32位的?可使用file命令查看.

staff-1:~# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), for GNU/Linux 2.6.0, stripped

staff-1:~# file /usr/bin/mplayer
/usr/bin/mplayer: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), for GNU/Linux 2.6.0, stripped

5) 一些编译前准备的实例,mplayer

linux32 ./configure --prefix=/usr --cc="gcc -m32" --target="i386-linux"
make
make install

注意:-cc,–target 参数不一定每个 configure 程序都提供,需灵活变通,其本质是设置了一些环境变量,可用手动配置.

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.

6) 注意和原来的共享库冲突,尽量不要编译到 /usr 目录下,否则影响其它64位的程序正常运作就得不尝失了.

7) 能不能100%编译成功? 不一定,如果 makefile 使用了64位的linker例如ld等,去link你编译出来32位的so的话,那就会报告不兼容. Good luck!!

相关参考:

阅读(2267) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~