Skip to content

GCC 8.2 Building on Mac OSX High Sierra (darwin 10.13.6)

Fengming Yuan edited this page Oct 12, 2018 · 4 revisions

GCC 8.2 Installation on Mac OSX High Sierra

NOTES: 2018-09-25 - The most recent OSX High Sierra has changed a lot from previous releases.

(1) openssl is a modified forked version, called libreSSL. So wget cannot be configured with this.

(2) clang compatiable GCC versioned as 4.2.1, but actually is not fully compatiable with GCC.

GNU tools/packages, required by GCC but not provided or upgraded by Apple Inc.

It's suggested that nearly most recent stable releases are downloaded from http://ftp.gnu.org.

(NOTE: those are actually needed for building other libraries. So in order to be automatically loaded, it's better to add the bin folder into $PATH and lib folder into $DYLD_LIBRARY_PATH (Mac doesn't have $LD_LIBRARY_PATH environmental variable anymore, but better have one by letting it =$DYLD_LIBRARY_PATH in .bashrc).

(1) autoconf-2.69

  ./configure --prefix=/usr/local/autotools
  make 
  sudo make install

make check takes a long time to finish. It seems no problem at all.

(2) automake-1.18

  ./configure --prefix=/usr/local/autotools
  make 
  sudo make install

make check takes a long time with a few FAILs.

(3) make-4.2.1

(Mac version is 3.8.1@2006)

  ./configure --prefix=/usr/local/autotools
  make all
  make check
  sudo make install

GCC Installation

GCC package from GNU ftp sites has compatibility issues with Mac OSX High Sierra. Fortunately it's patched well by a few open-source packages, like macport, homebrew, spack, etc.

FYI, a full package, including prerequisites and modifications discussed below, may be downloaded here.

(1) prerequisites

NOTES: wget not installed above due to openssl compatiblility issue. Have to do editing file ./contrib/downlad_prerequisties as following:

base_url='https://gcc.gnu.org/pub/gcc/infrastructure/', AND, commenting out all command lines involving wget

After untar the source package, enter the source code folder and download the prerequisites

cd gcc-8.2.0

vi ./contrib/download_prerequisties
**AS MENTIONED ABOVE**

./contrib/download_prerequisites
**SOME error messages on curl can be ignored, as long as the downloaded package OK**

(2)build and install

It's better to do the building and installing outside the source code folder.

mkdir gcc_builddir
cd gcc_builddir
../gcc-8.2.0/configure --prefix=/usr/local/gfortran-8.x --enable-languages=c,c++,fortran --enable-bootstrap --with-system-zlib --with-build-config=bootstrap-debug --disable-multilib CC=/usr/bin/gcc CXX=/usr/bin/g++
make all
sudo make install

make all usually takes a long time to finish.

Work-arounds on 1 (maybe 2) errors - very important

clang -static-libgcc error in stage 3 This error (very likely) appears from:

EXTRA_TARGET_FLAGS = \
    'AR=$$(AR_FOR_TARGET)' \
    'AS=$(COMPILER_AS_FOR_TARGET)' \
    'CC=$$(CC_FOR_TARGET) $$(XGCC_FLAGS_FOR_TARGET) $$(TFLAGS)' \
    'CFLAGS=$$(CFLAGS_FOR_TARGET)' \
    'CXX=$$(CXX_FOR_TARGET) -B$$r/$$(TARGET_SUBDIR)/libstdc++-v3/src/.libs \
    -B$$r/$$(TARGET_SUBDIR)/libstdc++-v3/libsupc++/.libs \
    $$(XGCC_FLAGS_FOR_TARGET) $$(TFLAGS)' \
    'CXXFLAGS=$$(CXXFLAGS_FOR_TARGET)' \
    'DLLTOOL=$$(DLLTOOL_FOR_TARGET)' \
    'GOC=$$(GOC_FOR_TARGET) $$(XGCC_FLAGS_FOR_TARGET) $$(TFLAGS)' \
    'GOCFLAGS=$$(GOCFLAGS_FOR_TARGET)' \
    'LD=$(COMPILER_LD_FOR_TARGET)' \
    'LDFLAGS=$$(LDFLAGS_FOR_TARGET)' \
    'LIBCFLAGS=$$(LIBCFLAGS_FOR_TARGET)' \
    'LIBCXXFLAGS=$$(LIBCXXFLAGS_FOR_TARGET)' \
    'NM=$(COMPILER_NM_FOR_TARGET)' \
    'OBJDUMP=$$(OBJDUMP_FOR_TARGET)' \
    'OBJCOPY=$$(OBJCOPY_FOR_TARGET)' \
    'RANLIB=$$(RANLIB_FOR_TARGET)' \
    'READELF=$$(READELF_FOR_TARGET)' \
    'WINDRES=$$(WINDRES_FOR_TARGET)' \
    'WINDMC=$$(WINDMC_FOR_TARGET)' \
    'XGCC_FLAGS_FOR_TARGET=$(XGCC_FLAGS_FOR_TARGET)' \
    'STAGE1_LDFLAGS=$$(POSTSTAGE1_LDFLAGS)' \ # <----- Here?
    'STAGE1_LIBS=$$(POSTSTAGE1_LIBS)' \
    "TFLAGS=$$TFLAGS"

TARGET_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS)

Workaround - commenting that marked line, AND, since this $(EXTRA_TARGET_FLAGS) is also inserted in the following line TARGET_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS), I duplicated the original as (EXTRA_TARGET1_FLAGS), which inserted into TARGET_FLAGS_TO_PASS, as following

TARGET_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET1_FLAGS)

(maybe) UNKNOWN error point to around Line 981 in Makefile in stage 3 or 4???

	$(MAKE) $(RECURSE_FLAGS_TO_PASS) `cat stage_final`-bubble

Workaround - find out which library or folder this break-out occurred (usually compiling message will print out where the building exit, AND then directly go to that folder and explicitly issue command 'make' to finish the compiling, AND back to build directory to continue the compilation

make check doesn't work, if no GNU autogen package.

MPICH Installation, with mixed compilers - clang, clang++, and gfortran

For CLM and PFLOTRAN, it needs MPI. MPICH is a good choice. It MUST be built with consistent compilers from above.

./configure CC=/usr/bin/gcc \
CXX=/usr/bin/g++ \
F77=/usr/local/gcc-8.x/bin/gfortran \
FC=/usr/local/gcc-8.x/bin/gfortran \
CPPFLAGS="-DgFortran -D_LARGE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include" \
CFLAGS="-I/usr/include" \
CXXFLAGS="-I/usr/include" \
FCFLAGS="-I/usr/local/gcc-8.x/include -I/usr/include" \
FFLAGS="-I/usr/local/gcc-8.x/include -I/usr/include" \
LDFLAGS="-L/usr/local/gcc-8.x/lib -L/usr/lib" \
--prefix=/usr/local/mpich-3.2-mixed --enable-static --enable-shared

NOTE: (1) using mac's system zlib (1.2.11), which in /usr/lib; (2) in the configuring above, \ is the line break sign and should be removed if in one line.

Then build and install, as following:

make all
make check
sudo make install

ANOTHER Tip: when building ELM with this mpich and clang/clang++/gfortran, there is an error relevant to __TEXT,text__ in libcsm_share.a. What you need to do is to modify building options related to -mcmodel=

 -mcmodel=small
Clone this wiki locally