Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 219
Jure1873 Avatar asked Aug 17 '10 08:08

Jure1873


People also ask

How can I tell if gcc is 32 or 64-bit?

To check this, we have to type this command. gcc –v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu ........... ........... ...........

How do I specify architecture in gcc?

If gcc -v shows GCC was configured with a --with-arch option (or --with-arch-32 and/or --with-arch-64 ) then that's what will be the default. Without a --with-arch option (and if there isn't a custom specs file in use) then the arch used will be the default for the target.

What is gcc m32?

The -m32 flag tells GCC to compile in 32-bit mode.

What will be output of program in compiler is 64-bit?

It depends upon the compiler if your processor is 8 bit then 2 if it 16 bit then 4 if it 64 then 8. Instead, if P is a character pointer, then also the output is 4.


1 Answers

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

like image 135
Alan Pearce Avatar answered Sep 27 '22 19:09

Alan Pearce