月度归档:2011年09月

在64位的环境下编译32位的应用程序

在64位的环境下编译32位的应用程序
背景知识: http://www.divms.uiowa.edu/local/linux_help/rh_ws3_amd64_faq.html

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

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

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

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″

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

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

相关参考:
•How to build 32-bit Wine on a 64-bit (x86-64) system

以下是其它人的讨论

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

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

这段没看懂,
第2点怎么设置的能说具体点吗??谢谢。

答复:
linux32 是一个设置环境变量 CHOST 的命令.可用 export CHOST=”i686-pc-linux-gnu” 代替

我自己尝试编译libmm在64位服务器上通过,参数如下
./configure CC=”gcc -m32″

nagios,本地发送报警邮件超时问题

最近在外网新搭了一套nagios系统,开始几天系统出了问题nagios还能发邮件通知,可最近出了问题老收不到邮件,手工在服务器上发邮件又可以,后来一查sendmail的日志和nagios的日志,发现sendmail的邮件只有邮件信息,没有进邮件队列.nagios那边的日志又报下面的警告:

[1292174436] Warning: Contact ‘wahaha’ service notification command ‘/usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: /boot\nHost: hostname\nAddress: 192.168.3.11\nState: CRITICAL\n\nDate/Time: Mon Dec 13 01:20:05 CST 2010\n\nAdditional Info:\n\nDISK CRITICAL – free space: /boot
8 MB (8% inode=99%):” | /bin/mail -s “** PROBLEM Service Alert: hostname//boot is CRITICAL **” wahaha@163.com’ timed out after 30 seconds

从上面的日志看,应该是发送超时了,也就是说设置的通知时间还不够能让sendmail发出邮件的时间,到这就好办了.通过修改nagios的配置文件nagios.cfg,将notification_timeout=30改为notification_timeout=120后重起nagios.发现已经能收到报警邮件了,到此问题解决!