compiling 32 bit application on 64 bit linux(x86_64)

hi all,
i have a 64 bit linux machine.

$uname -a
Linux SVRDELLD30 2.6.9-42.ELsmp #1 SMP Tue Aug 15 10:35:26 BST 2006 x86_64 x86_64 x86_64 GNU/Linux

here by default gcc creates 64 bit executable. but for some reason i want to create 32bit executable.

first i want to create 32 bit object files(.o files) and then i want to link those object files.

Please suggest me suitable gcc options.

Thanks and Regards,
uttam hoode

Just for the sake of saying so: You know you shouldn't be installing from source on RPM based distros, right? The proper way to do this for them is to create RPMs. If you're going to be running them on multiple platforms, just create a src.rpm, then "rpmbuild --rebuild thepackage" on each platform you need, or "rpmbuild --rebuild --target i386 thepackage" from your 64-bit system.

Next, why would you want to create 32-bit objects on a 64-bit platform? Wouldn't it make more sense to create them on a 32-bit platform? If you don't want to go through the hassle of setting up a 32 bit system, just use the installation CD for Gentoo as that should have everything you need. Also, if you're going to insist on installing things from source, I'd recommend you just go ahead and switch to Gentoo anyway.

To answer your question: Doesn't gcc create 32-bit when you do "--target=i386"?

32 bit programs are smaller and faster for programs that don't need more than 2Gig of memory. Most 64 bit processers (DEC Alpha excepted) support both 32bit and 64bit binaries, and most 64 bit operating systems support different memory models simultaneously on a process by process basis.

I've generally found that compilers on 64 bit systems build 32 bit code by default and require additional switches to produce 64 bit code. The linkers are normally able to work out what memory model the code is and will reject attempts to link code with differing models.

The gcc switch "-m32" can be used to generate 32-bit object files.