如何在Mac OS X Mountain Lion上编译可分发的Fortran二进制文件? [英] How to compile distributable Fortran binaries on Mac OS X Mountain Lion?

查看:113
本文介绍了如何在Mac OS X Mountain Lion上编译可分发的Fortran二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从Apple停止使用Xcode分发gfortran以来,我应该如何编译独立于体系结构的Fortran代码?我安装了Mac OS X Mountain Lion(10.8)和XCode 4.4,并且

Since Apple have stopped distributing gfortran with Xcode, how should I compile architecture independent Fortran code? I have Mac OS X Mountain Lion (10.8), and XCode 4.4 installed, with the Command Line Tools package installed.

据我所知,Xcode C/C ++/ObjC编译器使用 GNU编译器集合的分支,并以 llvm 作为后端;我认为后者可以为Intel和PPC架构编译和优化通用"二进制文件.

As far as I can tell, the Xcode C / C++ / ObjC compilers use a fork of the GNU compiler collection, with llvm as a backend; the latter I figure enables compiling and optimising "universal" binaries, for both Intel and PPC architectures.

我只找到一个专门为Mountain Lion发行gfortran二进制版本的网站: HPC 网站.但是,我没有得到这个来编译SciPy,后来在SciPy的自述文件中看到它是.

I've only found a single website that distributes a binary version of gfortran specifically for Mountain Lion: the HPC website. However, I failed to get this to compile SciPy, and later saw in SciPy's README that it is "known to generate buggy scipy binaries".

SciPy推荐的(免费)Fortran编译器是 CRAN的R 服务器,但尚未为Mountain Lion更新.它们为构建通用编译器提供了说明和脚本,但是,这又一次没有了.尚未更新山狮".

SciPy's recommended (free) Fortran compiler is the one on CRAN's R server, but this has not been updated for Mountain Lion yet. They provide instructions and a script for Building a Universal Compiler, but, again, this hasn't been updated for Mountain Lion yet..

G95项目自2010年以来就没有更新,因此我没有尝试过.有人在Mountain Lion上试过吗?

The G95 project hasn't had an update since 2010, so I didn't try it.. Anyone tried this on Mountain Lion?

我想这将是安装gfortran的最简单方法,但是port search gfortran一无所获,过去我对MacPorts并没有任何喜悦(对MacPorts毫无冒犯;它看起来非常活跃项目,但是我对Linux软件包管理器非常满意,我最喜欢的管理器是aptitude),因此在Mac OS X上,我过去是从源代码编译软件和库的.直到现在都没问题...

I guess this will be the easiest way to get gfortran installed, but port search gfortran comes up with nothing, and I've not had any joy with MacPorts in the past (no offence to MacPorts; it's looks like a very active project, but I've been spoilt with Linux package managers, my favourite manager being aptitude) so on Mac OS X I've compiled software and libraries from source code in the past. Never been a problem 'til now...

在过去的几天中,我在互联网上进行了大量的挖掘工作,我发现了其他Fortran编译器,但是我无法获得任何用于交叉编译通用二进制文件或编译SciPy的代码.

Having dug around on the internet a lot in the last couple of days, I've found other Fortran compilers, but I've failed to get any to cross-compile universal binaries, or to compile SciPy.

我编译了整个 GCC集合(v4.6.3),包括自动工具,automake,libtool和m4 -例如 GCC Wiki

I compiled the entire GCC collection (v4.6.3), including autotools, automake, libtool and m4 - like the GCC wiki and this blog describe - but the resulting compilers didn't compile universal binaries, probably because LLVM wasn't used as a backend.

DragonEgg 是一个"gcc插件,用LLVM代替了GCC的优化器和代码生成器……" .这看起来很有趣,但是我不知道如何使用它来编译"llvm-gfortran-4.x".能做到吗?

DragonEgg is a "gcc plugin that replaces GCC's optimisers and code-generators ... with LLVM". This looks interesting, but I don't know how I could use it to compile 'llvm-gfortran-4.x'. Can this be done?

Xcode随附的编译器是GCC v4.2(的分支?).但是,GCC的当前发行版和开发分支分别是4.6版和4.7版.显然,GNU许可证变更或其他原因阻止了Apple将其更新为更现代的GCC版本.因此,如果我要构建使用GCC gfortran v4.6制作的动态库,那么可以将它们与Xcode的本机编译器编译的C代码链接吗?至少,我认为生成的Mach-O二进制文件同时需要x86_64和i386代码路径. GCC是否提供与Apple GCC的向后兼容性?我知道gfortran具有 -ff2c标志,但是跨版本稳定吗?

The compiler that comes with Xcode is (a fork of?) GCC v4.2. But GCC's current release and development branches are versions 4.6 and 4.7, respectively. Apparently, a GNU license change, or something, stopped Apple from updating to more modern versions of GCC. So, if I was to build dynamic libraries made with GCC's gfortran v4.6, could they then be linked with C code compiled by Xcode's native compiler? At a minimum, I figure resulting Mach-O binaries need both x86_64 and i386 code paths. Do GCC provide backwards compatibility with Apple's (forks of?) GCC? I know gfortran has the -ff2c flag, but is this stable across versions?

我从源代码构建的GCC Fortran编译器不支持使用-arch编译标志.我在早期OSX版本(Snow Leopard to Lion)的CFLAGS和FFLAGS环境变量中都包含了标志-arch x86_64 -arch i386.当配置为使用Xcode的通用SDK构建应用程序或框架时,Python的distutils以及可能的其他OSX编译器都希望这些标志能够正常工作.

The GCC Fortran compiler I built from source didn't support the use of the -arch compile flag. I had been including the flags -arch x86_64 -arch i386 in both CFLAGS and FFLAGS environment variables on earlier OSX versions (Snow Leopard to Lion). Python's distutils, and probably other OSX compilers, expect these flags to work, when configured to build apps or frameworks, using Xcode's universal SDK.

如果您想知道我使用什么编译标志,我已经上传了我用于粘贴bin的脚本,在编译任何内容之前,我先使用source ~/.bash_devenv.

In case you're wondering what compile flags I use, I've uploaded the script I use to pastebin, which I source before I compile anything, using: source ~/.bash_devenv.

  • 创建使用-arch标志指定的ppc和intel(32位和64位)通用二进制文件.
  • 使二进制文件与XCode的链接器兼容.
  • 编译SciPy,没有错误(与numpy的distutils和f2py兼容).
  • Create ppc and intel (32 and 64bit) universal binaries, specified by using the -arch flags.
  • Makes binaries compatible with XCode's linker.
  • Compiles SciPy, giving no errors (compatible with numpy's distutils and f2py).

我使用Xcode的程度不高,但是与Xcode的集成肯定会使其他用户受益.甚至Intel仍然有问题将ifort集成到Xcode 4.4中,所以这不是我期望的工作..

I don't use Xcode so much, but integration with it would surely benefit other users. Even Intel are still having problems integrating ifort into Xcode 4.4, so this is not something I expect to work..

如果您已阅读以上所有内容,那么谢谢!您可能会说,我不反对从源代码构建自己的Fortran编译器,但是有可能吗?我错过了什么吗?可能是一个配置标志?如果还没有这样的编译器,那为什么不呢?!

If you read all the above, then thank you! You can probably tell that I'm not averse to building my own Fortran compiler from source, but is it even possible? Have I missed something? A configure flag maybe? And if such a compiler is not available yet, then why not?!

Apple在 opensource上提供了其GCC修补版本的源代码. .apple.com .这实际上包括gfortran的源代码,但是您知道吗-它不会(容易)编译.我正在编写一个构建脚本以使其正常工作.不幸的是,我不得不应用几个补丁,并了解.我认为这是要走的路.有什么理由不应该这样吗?如果我可以使用它,我将提供一个答案...

Apple provide the source code for their patched version of GCC, at opensource.apple.com. This actually includes the source code for gfortran, but what do you know - it doesn't compile (easily). I'm in the process of writing a build script to get this to work. Unfortunately, I've had to apply a couple of patches, and learn about "the Apple way" of building GNU software. This is the way to go I think. Any reasons why it shouldn't be? I'll update with an answer if I get it to work...

推荐答案

如果您尚未注意到这一点:在较新版本的Xcode中,您必须通过以下方式显式安装命令行工具:

In case you didn't already notice this: In newer versions of Xcode you have to explicitly install command line tools in the following way:

首选项->下载->组件

Preferences -> Downloads -> Components

然后单击命令行工具的安装"按钮.这包括gfortran:

And then click the "install" button for command line tools. This includes gfortran:

> gfortran -v
Using built-in specs.
Target: i686-apple-darwin10
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5664)

诚然,这不能解决我所有的fortran需求(在某些情况下,"./configure"脚本会抱怨说它们无法编译简单的fotran程序").

Admittedly, this does not solve all of my fortran needs (in some cases "./configure" scripts will complain that they cannot "compile a simple fotran program").

这篇关于如何在Mac OS X Mountain Lion上编译可分发的Fortran二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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