Linux gcc:在 32 位平台上编译 64 位二进制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7582218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gcc: Compile a 64-bit binary on 32-bit platform
提问by weekens
Is it possible to compile a 64-bit binary on a 32-bit Linux platform using gcc?
是否可以使用 gcc 在 32 位 Linux 平台上编译 64 位二进制文件?
采纳答案by rubenvb
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.
如果您安装了 multilib GCC,那么就像添加-m64
到命令行一样简单。如果编译器不是用多库支持构建的,编译器应该抱怨。
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.
为了链接,您需要标准库的所有 64 位对应版本。如果你的发行版有一个 multilib GCC,这些也应该在存储库中。
回答by wormsparty
You will need a gcc that will compile on 64 bits machines, eg x86_64-linux-gcc
. Check your distribution package manager.
您将需要一个可以在 64 位机器上编译的 gcc,例如x86_64-linux-gcc
. 检查您的分发包管理器。
回答by Franklin
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.
如果该-m64
选项不起作用,请进入 Synaptic 并搜索 gcc-multilib 或 g++-multilib 并安装该软件包。然后,使用-m64
选项进行编译。
回答by Asuka
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,.......
我想你可以先安装gcc-multilib
pacage。然后使用编译你的代码gcc -m64 yourcode
,你可以使用检查ELF文件file yourprogram
,输出应该是这样的
yourprogram: ELF 64-bit LSB executable,.......