misteryes
misteryes

Reputation: 2287

statically compiling 32 bit program on a 64 bit linux machine

I install libevent library using configure, make, make install. my computer is

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

I wrote a program which uses libevent. Since I want to distribute this program to many remote hosts where libevent is not installed. 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

so I want to use -m32 to compile

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!

Upvotes: 0

Views: 1507

Answers (1)

If you want to use your own compiled library in 32 bits mode (e.g. libevent) you should configure it with CC='gcc -m32' to have it compiled in 32 bits mode.

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

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...).

Upvotes: 1

Related Questions