简体   繁体   English

在64位linux机器上静态编译32位程序

[英]statically compiling 32 bit program on a 64 bit linux machine

I install libevent library using configure, make, make install . 我使用configure, make, make install安装libevent库。 my computer is 我的电脑是

[esolve@kitty esolve]$ uname -r
3.6.10-2.fc16.x86_64

I wrote a program which uses libevent. 我写了一个使用libevent的程序。 Since I want to distribute this program to many remote hosts where libevent is not installed. 由于我想将此程序分发到许多未安装libevent的远程主机。 So I want to compile the program statically, using 所以我想使用

gcc -o myprogram mypro.c /usr/local/lib/libevent.a -lpcap -lrt

now I notice some of the remote machines are 32 bits, not 64 bits 现在我注意到一些远程机器是32位的,而不是64位的

so I want to use -m32 to compile 所以我想用-m32来编译

gcc -m32 -o myprogram mypro.c /usr/local/lib/libevent.a -lpcap -lrt

but I got errors: 但我有错误:

/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(event.o)' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(log.o)' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(evutil.o)' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(select.o)' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(poll.o)' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(epoll.o)' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/local/lib/libevent.a(signal.o)' is incompatible with i386 output
collect2: ld returned 1 exit status

are there any workaround for this? 有什么解决方法吗? thanks! 谢谢!

If you want to use your own compiled library in 32 bits mode (eg libevent ) you should configure it with CC='gcc -m32' to have it compiled in 32 bits mode. 如果要在32位模式下使用自己的编译库(例如libevent ),则应使用CC='gcc -m32'对其进行configure ,以使其在32位模式下进行编译。

If you want to have both 32 & 64 bits versions of the same library you should build the library twice, with different configure options (don't forget to make clean between builds), perhaps changing the --prefix or --libexec-prefix 如果您想同时拥有32位和64位版本的同一个库,则应使用不同的configure选项(不要忘了在两次构建之间make clean )两次构建该库,也许更改--prefix--libexec-prefix

You could also consider having an entire 32 bits distribution in your chroot -ed environment (and then you'll need to bind mount some directories like /proc , /dev , etc...). 您还可以考虑在chroot环境中拥有完整的32位分发版(然后您需要bind安装某些目录,例如/proc/dev等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM