Mac OSX 10.6编译器:32位和64位令人费解的体验 [英] Mac OSX 10.6 compiler: a puzzling experience with 32 vs 64 bit

查看:167
本文介绍了Mac OSX 10.6编译器:32位和64位令人费解的体验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解OSX 10.6 snow leopard提供的gcc编译器,这主要是因为我缺乏64位环境的经验。

  main(){} 
$ gcc foo.c -o foo
$ file foo
foo:Mach-O 64位可执行文件x86_64
$ lipo -detailed_info foo
输入文件foo不是胖文件
非胖文件:foo是架构:x86_64

但是,我的架构被视为intel i386型(我有最新的Intel Core2 duo MacBook之一)

  $ arch 
i386

和编译器的目标是i686-apple-darwin10

  $ gcc --version 
i686-apple-darwin10-gcc-4.2 .1(GCC)4.2.1(Apple Inc. build 5646)

当然,如果我编译32位我得到一个32位可执行文件。

  $ gcc -m32 foo.c -o foo 
$ file foo
foo:Mach-O可执行文件i386

但我没有看到大局。编译器的默认设置是生成x86_64可执行文件,即使我说arch有一个32位的机器(为什么?Core2是64);即使(我猜)我正在运行一个32位内核;即使我有一个针对i686-apple-darwin平台的编译器。为什么?他们如何运行?我应该编译64还是32?



这个问题是由于我试图在mac上编译gcc 4.2.3,但是我遇到了一堆gmp问题, mpfr和libiberty获取(在某些情况下)为x86_64编译。我应该编译一切x86_64吗?如果是这样,目标是什么(不是i686-apple-darwin10我猜)?

感谢您的帮助

解决方案

Snow Leopard上的默认编译器是gcc4.2,其默认架构是x86_64。构建Mac软件的典型方法是在不同的通行证中构建多个体系结构,然后使用lipo来结合结果。 (lipo只会将单曲文件编译为多曲面文件,或者将曲拱从多曲面文件中删除,但在单曲文件中没有用处,正如您发现的那样)。

编译器的位数与任何内容无关。您可以使用64位编译器构建32位二进制文​​件,反之亦然。 (你认为编译器的目标实际上是它的可执行文件,这是不同的)。



内核的低成本与任何事情无关。您可以在32位内核上引导时构建和运行64位二进制文​​件,反之亦然。



重要的是当您链接时,无论您是否拥有适当的体系结构用于链接。您无法将32位版本与64位二进制文​​件链接起来,反之亦然。因此,重要的是要了解链接库的结构,确保它们是连贯的,然后构建相同体系结构的二进制文件,以便与您拥有的库链接。


I have trouble understanding the gcc compiler provided by OSX 10.6 snow leopard, mainly because of my lack of experience with 64 bits environments.

$ cat >foo.c
main() {}
$ gcc foo.c -o foo
$ file foo
foo: Mach-O 64-bit executable x86_64
$ lipo -detailed_info foo
input file foo is not a fat file
Non-fat file: foo is architecture: x86_64

However, my architecture is seen as an intel i386 type (I have one of the latest Intel Core2 duo MacBook)

$ arch
i386

and the compiler targets i686-apple-darwin10

$ gcc --version 
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)

Of course, if I compile 32 bits I get a 32 bit executable.

$ gcc -m32 foo.c -o foo
$ file foo
foo: Mach-O executable i386

but I don't get the big picture. The default setup for the compiler is to produce x86_64 executables, even if I have arch saying I have a 32 bit machine (why? Core2 is 64); even if (I guess) I am running a 32 bit kernel; even if I have a compiler targeting the i686-apple-darwin platform. Why? How can they run ? Should I compile 64 or 32 ?

This question is due to my attempt to compile gcc 4.2.3 on the mac, but I am having a bunch of issues with gmp, mpfr and libiberty getting (in some cases) compiled for x86_64. Should I compile everything x86_64 ? If so, what's the target (not i686-apple-darwin10 I guess)?

Thanks for the help

解决方案

The default compiler on Snow Leopard is gcc4.2, and its default architecture is x86_64. The typical way to build Mac software is to build multiple architectures in separate passes, then use lipo to combine the results. (lipo only compiles single-arch files into a multiple-arch file, or strips archs out of a multi-arch file. It has no utility on single-arch files, as you discovered.)

The bitness of the compiler has nothing to do with anything. You can build 32-bit binaries with a 64-bit compiler, and vice versa. (What you think is the "target" of the compiler is actually its executable, which is different.)

The bitness of the kernel has nothing to do with anything. You can build and run 64-bit binaries when booted on a 32-bit kernel, and vice versa.

What matters is when you link, whether you have the appropriate architectures for linking. You can't link 32-bit builds against 64-bit binaries or vice versa. So the important thing is to see what the architectures of your link libraries are, make sure they're coherent, then build your binary of the same architecture so you can link against the libraries you have.

这篇关于Mac OSX 10.6编译器:32位和64位令人费解的体验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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