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

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

问题描述

根据 Apple 的gcc 4.2.1 文档:

<块引用>

-拱形拱门
为指定目标编译建筑拱门.允许的值为i386"、x86_64"、ppc"和'ppc64'.多种选择有效,并且指示编译器生成通用"二进制文件,包括对象指定的每个架构的代码带-arch.此选项仅适用于汇编程序和库可用对于指定的每个架构.(仅限苹果)

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

gcc -arch i386 程序.c

gcc -m32 程序.c

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

解决方案

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

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

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

gcc -arch i386 -arch x86_64 foo.c

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

gcc -m32 -arch i386 -arch x86_64 foo.cgcc -m64 -arch i386 -arch x86_64 foo.cgcc -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

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

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