macos Apple 的 gcc,-arch i386 和 -m32 有什么区别?

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

Apple's gcc, what's the difference between -arch i386 and -m32?

macosgcc32-bit

提问by Jean Regisser

According to Apple's gcc 4.2.1 doc:

根据Apple 的 gcc 4.2.1 文档

-arch arch
Compile for the specified target architecture arch. The allowable values are 'i386', 'x86_64', 'ppc' and 'ppc64'. Multiple options work, and direct the compiler to produce “universal” binaries including object code for each architecture specified with -arch. This option only works if assembler and libraries are available for each architecture specified. (APPLE ONLY)

-arch arch
为指定的目标架构 arch 编译。允许的值为“i386”、“x86_64”、“ppc”和“ppc64”。多个选项起作用,并指示编译器生成“通用”二进制文件,包括使用 -arch 指定的每个体系结构的目标代码。只有当汇编器和库可用于指定的每个体系结构时,此选项才有效。(仅限苹果)

So what's the difference between these two calls:

那么这两个调用有什么区别:

gcc -arch i386 program.c

and

gcc -m32 program.c

Is it just that -archis more powerful as it's more flexible and can produce universal binaries when specifiying multiple archs?

只是-arch更强大,因为它更灵活,并且在指定多个拱门时可以生成通用二进制文件?

采纳答案by jitter

I'm not sure but from reading the man page I get to similar conclusions as you do.

我不确定,但是通过阅读手册页,我得出了与您类似的结论。

I guess the only real difference is that -archcan be used to create universal binaries.

我想唯一真正的区别是-arch可用于创建通用二进制文件。

As this works to create universal binaries

因为这可以创建通用二进制文件

gcc -arch i386 -arch x86_64 foo.c

but you actually can't be sure what the semantics of the following should be (they probably are even invalid syntax). Especially the third should be invalid as the man pages says to generate for for 32- or 64-bit environments.

但您实际上无法确定以下的语义应该是什么(它们甚至可能是无效的语法)。特别是第三个应该是无效的,因为手册页说为 32 位或 64 位环境生成。

gcc -m32 -arch i386 -arch x86_64 foo.c
gcc -m64 -arch i386 -arch x86_64 foo.c
gcc -m32 -m64 -arch i386 -arch x86_64 foo.c
-m32
-m64
    Generate code for a 32-bit or 64-bit environment.  The 32-bit environment
    sets int, long and pointer to 32 bits and generates code that runs on any
    i386 system.  The 64-bit environment sets int to 32 bits and long and
    pointer to 64 bits and generates code for AMDs x86-64 architecture.
    For darwin only the -m64 option turns off the -fno-pic and 
    -mdynamic-no-pic options.

-arch //already included in question
-m32
-m64
    Generate code for a 32-bit or 64-bit environment.  The 32-bit environment
    sets int, long and pointer to 32 bits and generates code that runs on any
    i386 system.  The 64-bit environment sets int to 32 bits and long and
    pointer to 64 bits and generates code for AMDs x86-64 architecture.
    For darwin only the -m64 option turns off the -fno-pic and 
    -mdynamic-no-pic options.

-arch //already included in question