24

Is it possible to compile a 64-bit binary on a 32-bit Linux platform using gcc?

weekens
  • 8,064
  • 6
  • 45
  • 62

4 Answers4

31

If you have a multilib GCC installed, it's as simple as adding -m64 to the commandline. The compiler should complain if it is not built with multilib support.

In order to link, you'll need all the 64-bit counterparts of the standard libraries. If your distro has a multilib GCC, these should also be in the repositories.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • You meant, I need 64-bit counterparts. – weekens Sep 28 '11 at 12:24
  • weekens: uh, yeah. Fixed that :) – rubenvb Sep 28 '11 at 13:24
  • Note that this applies to all architectures supported by the compiler. For example this is how cross-compiling is done for ARM devices. You can of course compile stuff on your platform (if there are sufficient resources) however most people use cross-compiling. Raspberry Pi is a fine example. The official OS is Rasbian which is a Debian basically so you can compile ARM binaries for the Rasbian (including the customized GCC shipped by the Raspberry Foundation for the Pi's processor from your PC (doesn't matter if it's 32 or 64bit). You just need to add support for ARM. – rbaleksandar May 07 '16 at 13:26
2

Go into Synaptic and search for gcc-multilib or g++-multilib and install the package, if the -m64 option does not work. Then, compile with the -m64 option.

Franklin
  • 21
  • 1
1

I think you could install gcc-multilib pachage first. And then compile your code using gcc -m64 yourcode, you cound check the ELF file using file yourprogram, the output should be like this yourprogram: ELF 64-bit LSB executable,.......

Asuka
  • 301
  • 4
  • 16
1

You will need a gcc that will compile on 64 bits machines, eg x86_64-linux-gcc. Check your distribution package manager.

wormsparty
  • 2,481
  • 19
  • 31