Force gcc to compile 32 bit programs on 64 bit platform

[Origin]: http://stackoverflow.com/questions/3501878/force-gcc-to-compile-32-bit-programs-on-64-bit-platform

I’ve got a proprietary program that I’m trying to use on a 64 bit system.

When I launch the setup it works ok, but after it tries to update itself and compile some modules and it fails to load them.

I’m suspecting it’s because it’s using gcc and gcc tries to compile them for a 64 bit system and therefore this program cannot use these modules.

Is there any way (some environmental variables or something like that) to force gcc to do everything for a 32 bit platform. Would a 32 bit chroot work?

shareedit

You need to make GCC use the -m32 flag.

You could try writing a simple shell script to your $PATH and call it gcc (make sure you don’t overwrite the original gcc, and make sure the new script comes earlier in $PATH, and that it uses the full path to GCC.

I think the code you need is just something like /bin/gcc -m32 $* depending on your shell (the $*is there to include all arguments, although it might be something else – very important!)

shareedit

You’ll also need the 32bit C library, as well as 32 bit versions of whatever external libraries the program links against in some cases. – Tim Post Aug 17 ’10 at 11:12

Indeed. Standard libraries: C: apt-get install gcc-multilib; C++: apt-get install g++-multilib. – Bart Nov 20 ’14 at 17:13

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s