Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gcc instead of clang in ghci or ghc

On Mac OSX 10.9, the default c compiler bundled with Xcode is clang. I installed gcc-4.9 with homebrew. Now I have two different gccs, one is clang, the other is gcc. The default is clang.

I want to use gcc when compiling Haskell files with ghc, and I want also gcc when I launch ghci. How to do this change?

like image 949
eccstartup Avatar asked Dec 03 '13 10:12

eccstartup


People also ask

Which one is better GCC or Clang?

None is better. Each will optimize the code better in some cases and worse in some other cases. Comparing unoptimized code is pointless. For compile time, Clang is better because it produce output much faster than gcc. But in x86, Intel compiler (ICC) often produce better optimized code when optimizing for speed.

How do I use compiled code with GHCi?

Note the -dynamic flag to GHC: GHCi uses dynamically-linked object code (if you are on a platform that supports it), and so in order to use compiled code with GHCi it must be compiled for dynamic linking. At any time you can use the command :show modules to get a list of the modules currently loaded into GHCi:

How do I invoke GHCi from GHCi?

Invoking GHCi ¶ GHCi is invoked with the command ghci or ghc --interactive. One or more modules or filenames can also be specified on the command line; this instructs GHCi to load the specified modules or filenames (and all the modules they depend on), just as if you had said :load modules at the GHCi prompt (see GHCi commands ).

Does GHCi maintain a lexical call stack?

Ideally GHCi would maintain a separate lexical call stack in addition to the dynamic call stack, and in fact this is exactly what our profiling system does ( Profiling ), and what some other Haskell debuggers do. For the time being, however, GHCi doesn’t maintain a lexical call stack (there are some technical challenges to be overcome).


1 Answers

Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371

  1. Type ghc --print-libdir

    The output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3

  2. Go to that directory and edit the settings file.

  3. There'll be a line indicating the path to the C compiler. It'll probably say /bin/gcc

  4. 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)

like image 149
Carter Tazio Schonwald Avatar answered Sep 19 '22 16:09

Carter Tazio Schonwald