gcc: Compile a 64-bit binary on 32-bit platform
Solution 1
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.
Solution 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.
Solution 3
You will need a gcc that will compile on 64 bits machines, eg x86_64-linux-gcc
. Check your distribution package manager.
Solution 4
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,.......
weekens
I'm a software developer, used to work for telecom and Web. Started career at 2002. My key competences are Java and С++ server programming. Another competence is Linux server administration. Also trying myself in client and server Web programming with JavaScript.
Updated on June 21, 2020Comments
-
weekens almost 4 years
Is it possible to compile a 64-bit binary on a 32-bit Linux platform using gcc?