C语言 什么时候应该使用 gcc 的 -m32 选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2426478/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:49:45  来源:igfitidea点击:

When should -m32 option of gcc be used?

cgcc32bit-64bit

提问by Jay

I am writing a program which if I compile on a Suse 10 32-bit system without adding the -m32option and execute it on Suse 10 64-bit, it works fine.

我正在编写一个程序,如果我在 Suse 10 32 位系统上编译而不添加-m32选项并在 Suse 10 64 位上执行它,它工作正常。

In this case, is it not required for me to add the -m32option?

在这种情况下,我不需要添加-m32选项吗?

Can we execute programs built on 32-bit systems directly on their 64-bit counterparts without any side-effects? Or are there any updates or changes required?

我们能否直接在 64 位系统上执行基于 32 位系统的程序而没有任何副作用?或者是否需要任何更新或更改?

回答by AProgrammer

There is no problems in running 32 bits executables on 64 bit OS (as long as 32 bit dynamic libraries are present and found).

在 64 位操作系统上运行 32 位可执行文件没有问题(只要存在并找到 32 位动态库)。

-m32 is there to compile 32 bits objects on a compiler configured to compile 64 bits objects by default.

-m32 用于在配置为默认编译 64 位对象的编译器上编译 32 位对象。

回答by Earlz

As long as the OS supports both 32bit and 64bit programs (hint: not all do, such as OpenBSD) on a 64bit OS, then you shouldn't have any kind of problems as long as you have all of the 32bit dependencies for it..

只要操作系统在 64 位操作系统上同时支持 32 位和 64 位程序(提示:并非所有程序都支持,例如 OpenBSD),那么只要您拥有所有 32 位依赖项,就不会有任何问题。 .