在Mac上安装GNU GCC [英] Install GNU GCC on mac

查看:1768
本文介绍了在Mac上安装GNU GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近对Xcode 5中包含的新的clang编译器感到失望。我想知道在OS X上安装GNU GCC的最好方法是什么。

I have recently become frustrated with the new clang compiler included with Xcode 5. I was wondering what the best way to install GNU GCC on OS X would be.

需要考虑的事项:


  • 我不想使用MacPorts,fink,homebrew或任何其他第三方软件包管理器。
  • 我想使用最新的GCC,如果可能的话从源代码编译。

  • 我需要现有的GCC(hardlink到clang)

  • 我希望尽可能避免修改代码。

编辑:成功!使用GCC 4.9.2(使用GMP 5.1.3,MPFR 3.1.2,MPC 1.0.2,ISL 0.12.2和CLooG 0.18.1)我成功构建了GCC。以下提示:

Success! Using GCC 4.9.2 (with GMP 5.1.3, MPFR 3.1.2, MPC 1.0.2, ISL 0.12.2, and CLooG 0.18.1) I succesfully built GCC. Tips to take from here:


  • 确保使用ISL和CLooG。是的,他们是可选的,但他们做一个更优化的编译器,我有麻烦建设没有他们。确保您使用的是ISL 0.12,不是最新版本(0.14)。

  • 如果可能,请使用独立的开发人员工具 XCode。 (XCode有一些错误的标题,虽然我没有注意到任何问题,建立GCC我有与其他软件(例如GPG)的问题。

  • 我建议将所有的来源gcc目录,而不是单独构建和安装(这样更快)

  • 确保 > CC = clang CXX = clang ++ 因此GCC知道它没有被GCC编译。

  • , ,调用 make 与 -j8 ,否则构建将需要约4小时! ( -j8 ,在我的Mid-2012 MBP和8gb RAM上花了1 1/3小时。)( make -j8 表示 make 可以同时构建8个线程(4核+ HT),而在双核机器上,您将运行 make -j4 。)

  • Make sure you use ISL and CLooG. Yes, they are optional, but they make a more optimised compiler and I had trouble building without them. Make sure you use ISL 0.12, not the latest version (0.14).
  • If possible, use the standalone Developer Tools, not XCode. (XCode has some buggy headers, and while I didn't notice any issues building GCC I have had issues with other software (e.g. GPG)).
  • I recommend putting all your sources in the gcc directory, rather than building and installing separately (it's faster this way)
  • Make sure you invoke configure with CC=clang CXX=clang++ so GCC knows it isn't being compiled by GCC.
  • Definitely, definitely, definitely, invoke make with -j8, or otherwise the build will take about 4 hours! (With -j8, it took 1 1/3 hours on my Mid-2012 MBP with 8gb RAM.) (make -j8 means make can build 8 threads simultaneously (4 cores + HT), whereas on a 2-core machine you would run make -j4.)

希望这有帮助!

推荐答案

我这样做的方式是:


  1. 下载GCC的源代码和众多支持包。这些指令位于GCC源代码中的 gcc-4.xy / INSTALL / index.html 文件中,或者在 http://gcc.gnu.org/install/

  • GNU Multiple Precision Library (GMP) version 4.3.2 (or later) from http://gmplib.org/.
  • MPFR Library version 2.4.2 (or later) from http://www.mpfr.org/.
  • MPC Library version 0.8.1 (or later) from http://www.multiprecision.org/.
  • ISL Library version 0.11.1 from ftp://gcc.gnu.org/pub/gcc/infrastructure/.
  • CLooG 0.18.0 from ftp://gcc.gnu.org/pub/gcc/infrastructure/.

使用脚本将GCC和支持库的源代码提取到目录中,创建对象目录,运行构建。

Use a script to extract the source for GCC and the support libraries into a directory, create the object directory, and run the build.

这是我用于GCC 4.8.2的脚本:

This is the script I used for GCC 4.8.2:

GCC_VER=gcc-4.8.2
tar -xf ${GCC_VER}.tar.bz2 || exit 1

(
cd ${GCC_VER} || exit

cat <<EOF |
    cloog 0.18.0 tar.gz 
    gmp 5.1.3 tar.xz 
    isl 0.11.1 tar.bz2 
    mpc 1.0.1 tar.gz 
    mpfr 3.1.2 tar.xz
EOF

while read file vrsn extn
do
    (
    set -x
    tar -xf "../$file-$vrsn.$extn" &&
    ln -s "$file-$vrsn" "$file"
    )
done
)

mkdir ${GCC_VER}-obj
cd ${GCC_VER}-obj
../${GCC_VER}/configure --prefix=$HOME/gcc/gcc-4.8.2
make -j8 bootstrap

完成后,运行安装。然后添加 $ HOME / gcc / gcc-4.8.2 / bin (在 - 前缀 / usr / bin

When that finishes, run the install too. Then add $HOME/gcc/gcc-4.8.2/bin (the name you specify in --prefix plus /bin) to your PATH ahead of /usr/bin.

使用5400转盘旋转磁盘的一个体面的MacBook Pro,需要一个小时或两个编译所有(使用 -j8 选项到 make ),并且在编译时需要多个千兆字节的磁盘空间。 SSD是非常好的(当然更快)!

With a decent MacBook Pro with a 5400 rpm spinning disk, it takes an hour or two to compile everything (using the -j8 option to make), and requires multiple gigabytes of disk space while compiling. SSD is nice when doing this (definitely faster)!

GCC 4.9.0发布于2014-04-22。我使用基本相同的过程安装它,但使用CLooG 0.18.1和ISL 0.12.2(必需更新)和GMP 5.1.3(和6.0.0a),MPC 1.0.2(或1.0.1)和MPFR 3.1.2在Mac OS X 10.9.2 Mavericks和Ubuntu 12.04衍生品。注意 gmp-6.0.0a.tar.xz 解压到目录 gmp-6.0.0 (不是<$

GCC 4.9.0 was released on 2014-04-22. I've installed it using basically the same process, but with CLooG 0.18.1 and ISL 0.12.2 (required updates) and GMP 5.1.3 (and 6.0.0a), MPC 1.0.2 (or 1.0.1) and MPFR 3.1.2 on Mac OS X 10.9.2 Mavericks and an Ubuntu 12.04 derivative. Beware that the gmp-6.0.0a.tar.xz extracts into directory gmp-6.0.0 (not gmp-6.0.0a as you might expect).

截至目前为止,您可能会遇到下列问题:c $ c> gmp-6.0.0a 2014-10-21,GCC 4.9.1(和其他早期版本)不能在Mac OS X 10.10 Yosemite上构建。

As of 2014-10-21, GCC 4.9.1 (and other earlier versions) do not readily build on Mac OS X 10.10 Yosemite.

这篇关于在Mac上安装GNU GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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