Skip to content

Instantly share code, notes, and snippets.

@cartazio
Last active May 28, 2019 00:35
Show Gist options
  • Save cartazio/7131371 to your computer and use it in GitHub Desktop.
Save cartazio/7131371 to your computer and use it in GitHub Desktop.
xcode 5 + OS X 10.9 mavericks GHC work around nuttiness

PSA :

just use GHC for OSX https://ghcformacosx.github.io

the rest of these directions are preserved for historical purposes

TLDR version, if you have homebrew

xcode-select --install ; brew tap homebrew/versions ;   brew tap homebrew/dupes \
brew install apple-gcc42 ; brew link apple-gcc42 

NB: the xcode-select --install is how you (re)install the mavericks xcode 5 CLI tools, you HAVE to do that. Either way, you should make sure you have CLI tools installed.

NB: apple-gcc42 is quite old, but doesn't require a build from source (so it can work right away). Those who have a bit more patience and want a more modern GCC can use brew install gcc49 or the like (though the build may take a while).

then edit the settings file as follows:

  • type "ghc-pkg list"

  • the first line of the output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/package.conf.d

  • go one directory up to /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/

  • open the settings file.

  • there'll be a line indicating the path to the c compiler. It'll probably say /bin/gcc

  • change that line to /usr/local/bin/gcc-4.8 (or whichever gcc version you brew installed, such as /usr/local/bin/gcc-4.2)

  • you may also want to make sure that the gcc in your PATH points to this gcc. Many tools have calling gcc hard coded in.

  • if you point gcc to your gcc, be sure to also point cc to that gcc, and g++ to the g++ associated with that gcc. (otherwise when you're building a project that uses a mix of c and c++, you'll have really really weird build errors)

one Alternative approach that works with xcode 5 and doesnt need HomeBrew (by @lukexi and Manuel) here http://justtesting.org/post/64947952690/the-glasgow-haskell-compiler-ghc-on-os-x-10-9

another alternative see http://www.haskell.org/pipermail/haskell-cafe/2013-October/111174.html and https://gist.github.com/mzero/7245290 for tools that should work on a stock mac using haskell platform (work courtesy of Mark Lentczner)

NB: both these approaches use Clang, which hits some exotic corner cases in CPP still, along with some build system quirks.

more explanations

to recap -- the fastest way to have a working GHC / haskell platform install is the following. Much faster than the brew install approach, and uses the builds maintained by the official haskell platform folks.

so the total newb supervised install would be like

  1. make sure the person has up to date CLI tools installed

  2. brew install apple-gcc42

(3,optional, just skip to step 4 if you already have GHC)

  1. install GHC or haskell platform etc (either) and make sure you've appropriately fixed up your path. 64 bit build here http://www.haskell.org/platform/mac.html

  2. do my horrible edit your settings file thing to point the compiler to gcc42

(originaly shared here on reddit

the fastest work around is to use brew to build your own copy of GCC

brew install apple-gcc42 is fastest, i've used brew install gcc48

then type "ghc-pkg list"

the first line will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/package.conf.d

go one directory up to /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/

then open the settings file.

there'll be a line indicating the path to the c compiler. It'll probably say "/bin/gcc"

change that line to "/usr/local/bin/gcc-4.8" (or whichever gcc version you brew installed, such as "/usr/local/bin/gcc-4.2")

enjoy life, haskell and mavericks/xcode 5.

NB: this is the power user fix. I recommend that most users instead do one of the approaches in http://www.haskell.org/pipermail/haskell-cafe/2013-September/110320.html

(directions for step 4 laid out below in the comments)

@cartazio
Copy link
Author

replicating the reddit remark for posterity

the fastest work around is to use brew to build your own copy of GCC

brew install apple-gcc42 is fastest, i've used brew install gcc48

then type "ghc-pkg list".

the first line will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/package.conf.d

go one directory up to
/Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/

then open the settings file.

there'll be a line indicating the path to the c compiler. It'll probably say "/bin/gcc"

change that line to "/usr/local/bin/gcc-4.8" (or whichever gcc version you brew installed)

enjoy life, haskell and mavericks.

NB: this is the power user fix. I recommend that most users instead do one of the approaches in http://www.haskell.org/pipermail/haskell-cafe/2013-September/110320.html

@edsko
Copy link

edsko commented Mar 28, 2014

When compiling ghc 7.4.2 (and probably also 7.6), either compile with

make USE_DTRACE=NO

or else cherry-pick ghc/ghc@8878541. Thanks Austin for helping with this.

@LokiClock
Copy link

As far as I chose the interpretation of adding things to my path as creating a .bash_profile file in HOME and filling it with PATH="/usr/local/bin:$PATH", you must also add the following to your PATH, or else weird things happen like if you upgrade from cabal 1.16 to cabal 1.20 then the new version won't be detected:
$HOME/Library/Haskell/bin

Fix discovered here: acowley/GLUtil#12
I forget things about the build system, but if I recall the fix is adding Cabal's local install location to PATH and not just the global install location. If that's the case, should I be installing the newer cabal through a global install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment