苹果的gcc,-arch i386和-m32有什么区别? [英] Apple's gcc, what's the difference between -arch i386 and -m32?

查看:337
本文介绍了苹果的gcc,-arch i386和-m32有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Apple's gcc 4.2.1 doc


-arch arch

编译为指定的目标
架构拱。允许的
值是'i386','x86_64','ppc'和
'ppc64'。有多个选项可以工作,
指示编译器为每个指定
的体系结构生成
通用二进制文件,包括对象
代码。此选项仅适用于
汇编程序和库对于指定的每种体系结构都可用的

(APPLE ONLY)

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

 gcc -arch i386 program.c 

 gcc -m32 program.c 

只是 -arch 更强大,因为它更灵活,可以产生通用二进制文件,当指定多个arch?

解决方案

我不确定,但从阅读手册页我得到类似的结论, 。

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



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

  gcc -arch i386 -arch x86_64 foo.c 

但是您实际上无法确定以下的语义应该是什么(他们可能甚至是无效的语法)。特别是第三个应该是无效的,因为手册页说为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
为32位或64位环境生成代码。 32位环境
设置int,long和指向32位的指针,并生成在任何
i386系统上运行的代码。 64位环境将int设置为32位,将long和
指针设置为64位,并为AMD x86-64架构生成代码。
对达尔文而言,只有-m64选项会关闭-fno-pic和
-mdynamic-no-pic选项。

-arch //已包含在问题中



According to Apple's gcc 4.2.1 doc:

-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)

So what's the difference between these two calls:

gcc -arch i386 program.c

and

gcc -m32 program.c

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

解决方案

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 -arch can be used to create universal binaries.

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.

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

这篇关于苹果的gcc,-arch i386和-m32有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆