Reputation: 8282
Is it possible to compile a 64-bit binary on a 32-bit Linux platform using gcc?
Upvotes: 25
Views: 26391
Reputation: 311
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,.......
Upvotes: 1
Reputation: 21
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.
Upvotes: 2
Reputation: 76519
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.
Upvotes: 31
Reputation: 2499
You will need a gcc that will compile on 64 bits machines, eg x86_64-linux-gcc
. Check your distribution package manager.
Upvotes: 1