Building GCC on OS X 10.11

后端 未结 3 1305
执笔经年
执笔经年 2021-01-07 03:43

Building GCC (latest revision) on OS X 10.11.1 here, using the command line:

../gccx/configure --with-gmp=\"/opt/local\" --with-mpfr=\"/opt/local\" \\
    --         


        
3条回答
  •  孤街浪徒
    2021-01-07 04:10

    General discussion

    Building GCC on Mac OS X is an occasionally fraught process. I've had various issues with various versions of GCC and various versions of Mac OS X over the years. You can see an earlier explanation of what I did in Install GCC on Mac OS X — that was for building GCC 4.8.x on Mavericks 10.9.x (or possibly Mountain Lion 10.8.x); it also reports success building GCC 4.9.0 on Mavericks 10.9.x, but failure to do so on Yosemite 10.10.x.

    This is an updated recipe for building GCC 5.2.0 on Mac OS X 10.11.1 El Capitan. It starts off using XCode 7.1.1 — I don't know which other versions of XCode are OK.

    Note that El Capitan has a feature SIP (System Integrity Protection) that was not in Yosemite and earlier versions. This means you cannot create arbitrary directories under /usr any more. I used to install in /usr/gcc/vX.Y.Z; that is no longer permitted in El Capitan. One major change, therefore, is that I now install in /opt/gcc/v.X.Y.Z.

    I've found that having DYLD_LIBRARY_PATH set is problematic — especially on El Capitan. In a major break from the past, I'm now not setting that at all. Note that the scripts unset it. Note too that the script explicitly sets the phase 1 compilers CC and CXX to /usr/bin/clang and /usr/bin/clang++ respectively (the XCode compilers). The current versions of GCC require a capable C++ compiler instead of (or as well as) a C compiler.

    I have occasionally had problems with libiconv, but at the moment I've evaded them by not having my own version installed. Similarly, I've occasionally had problems with some awk scripts in the GCC source. I had to hack it/them to get it to work OK. However, with release copy of GCC 5.2.0 source, I seem to be able to build directly out of the box.

    If you've only got a single disk partition, this next point isn't crucial. If you have multiple disks, either make sure the target directory does not exist or ensure that its name is exactly what you want. On the machines at work (not Macs but Linux machines, etc), I still use /usr/gcc/vX.Y.Z as the 'official' install location, but the software ends up in some arbitrary file system where there's enough space, such as /work4/gcc, and eventually there is a symlink such that /usr/gcc/vX.Y.Z gets to /work4/gcc/vX.Y.Z. However, it is crucial that /work4/gcc/vX.Y.Z does not exist while GCC is being compiled because it will resolve the name via realpath() or its equivalent and embed /work4/gcc/vX.Y.Z into the binaries, rather than the neutral name /usr/gcc/vX.Y.Z. This limits the portability of the installation; any other machine that it is moved to has to have a directory /work4/gcc/vX.Y.Z, even though you asked to install it in /usr/gcc/vX.Y.Z.

    Compiling GCC 5.2.0 on Mac OS X 10.11.1 with XCode 7.1.1

    I had to work with down-versions of both GMP (5.1.3 instead of 6.0.0a) and ISL (0.14 instead of 0.15). The builds for the later versions both caused me trouble.

    Note that I put the library code for GMP, MPC, MPFR, ISL and Cloog (see the GCC pre-requisites) in the GCC source directory so that GCC builds its own versions of these libraries. I've found that its the simplest way to ensure that GCC locates these libraries correctly.

    Target directory: /opt/gcc/v5.2.0

    Build time was about 2h 15m on a 17" MacBook Pro (early 2011) running Intel Core i7 at 2.3 GHz, with 16 GiB 1333 MHz DDR3 main memory, and a 750 GB 5400 rpm hard disk drive. The source occupies about 850 MiB; the build tree ends up at about 4.6 GiB — you need plenty of disk space. The installed code ends up at about 420 MiB.

    Script used — extract-gcc-5.2.0.sh

    #!/bin/bash
    
    unset DYLD_LIBRARY_PATH
    
    TAR=tar
    VER_NUM=5.2.0
    GCC_VER=gcc-${VER_NUM}
    TGT_BASE=/opt/gcc
    TGT_DIR=${TGT_BASE}/v${VER_NUM}
    CC=/usr/bin/clang
    CXX=/usr/bin/clang++
    
    extract() {
        echo "Extract $1"
        $TAR -xf $1
    }
    
    if [ ! -d "$GCC_VER" ]
    then extract ${GCC_VER}.tar.bz2 || exit 1
    fi
    
    (
    cd ${GCC_VER} || exit
    
    nbncl <&2; exit 1;
        fi
        if [ ! -d "$file-$vrsn" ]
        then
            (
            set -x
            extract "$tarfile" &&
            ln -s "$file-$vrsn" "$file"
            ) || exit 1
        fi
    done
    )
    
    if [ $? = 0 ]
    then
        mkdir ${GCC_VER}-obj
        cd ${GCC_VER}-obj
        ../${GCC_VER}/configure --prefix="${TGT_DIR}" \
            CC="${CC}" \
            CXX="${CXX}"
        make -j8 bootstrap
    fi
    

    Script nbncl — non-blank, non-comment lines

    #!/usr/bin/env perl
    #
    # Non-blank, non-comment lines only
    
    use warnings;
    use strict;
    
    while (<>)
    {
        chomp;
        s/\s+$//;
        s/\s*#.*$//;
        print "$_\n" unless /^$/;
    }
    

提交回复
热议问题