You may specify that a different program be used for one
of the phases of the compilation system, in place of whatever
the ghc has wired into it. For example, you
might want to try a different assembler. The following options
allow you to change the external program used for a given
The C pre-processor cpp is run
over your Haskell code only if the -cpp
option is given. Unless you are
building a large system with significant doses of
conditional compilation, you really shouldn't need
Define macro symbol in the
usual way. NB: does not affect
-D macros passed to the C compiler
when compiling via C! For those, use the
-optc-Dfoo hack… (see Section 4.12.2).
Undefine macro symbol in the
Specify a directory in which to look for
#include files, in the usual C
The GHC driver pre-defines several macros when processing
Haskell source code (.hs or
If defined, this means that GHC supports the
language defined by the Haskell 98 report.
In GHC 4.04 and later, the
macro is defined as having the value
If defined to n, that
means GHC supports the Haskell language defined in the
Haskell report version 1.n.
Currently 5. This macro is deprecated, and will probably
disappear in future versions.
For version n of the GHC
system, this will be #defined to
100n. For example, for version
5.00, it is 500.
With any luck,
will be undefined in all other implementations that
support C-style pre-processing.
(For reference: the comparable symbols for other
for nhc98, and
NB. This macro is set when pre-processing both
Haskell source and C source, including the C source
generated from a Haskell module
(i.e. .hs, .lhs,
.c and .hc
This symbol is defined when pre-processing Haskell
(input) and pre-processing C (GHC output). Since GHC from
verion 4.00 now supports concurrent haskell by default,
this symbol is always defined.
Only defined when -parallel is in
use! This symbol is defined when pre-processing Haskell
(input) and pre-processing C (GHC output).
A custom pre-processor is run over your Haskell
source file only if the -F option
Running a custom pre-processor at compile-time is in some
settings appropriate and useful. The -F
option lets you run a pre-processor as part of the overall
GHC compilation pipeline, which has the advantage over
running a Haskell pre-processor separately in that it
works in interpreted mode and you can continue to take
reap the benefits of GHC's recompilation checker.
The pre-processor is run just before the Haskell
compiler proper processes the Haskell input, but after
the literate markup has been stripped away and (possibly)
the C pre-processor has washed the Haskell input.
Use cmd as the Haskell
pre-processor. When invoked, the
cmd pre-processor is given at
least three arguments on its command-line: the first
argument is the name of the original source file, the second
is the name of the file holding the input, and the third is
the name of the file where
cmd should write its output to.
Additional arguments to the
cmd pre-processor can be passed
in using the -optF option. These are fed to
cmd on the command line after the
three standard input and output arguments.
Use GHC's native code generator rather than
compiling via C. This will compile faster (up to twice as
fast), but may produce code that is slightly slower than
compiling via C. -fasm is the default
when optimisation is off (see Section 4.11).
Compile via C instead of using the native code
generator. This is default for optimised compilations,
and on architectures for which GHC doesn't have a native
Omit code generation (and all later phases)
altogether. Might be of some use if you just want to see
dumps of the intermediate compilation phases.
GHC has to link your code with various libraries, possibly
including: user-supplied, GHC-supplied, and system-supplied
(-lm math library, for example).
Link in the lib library.
On Unix systems, this will be in a file called
which resides somewhere on the library directories path.
Because of the sad state of most UNIX linkers, the
order of such options does matter. If library
foo requires library
bar, then in general
come before-lbar on the
There's one other gotcha to bear in mind when using
external libraries: if the library contains a
main() function, then this will be
linked in preference to GHC's own
(eg. libf2c and libl
have their own main()s). This is
because GHC's main() comes from the
HSrts library, which is normally
included after all the other
libraries on the linker's command line. To force GHC's
main() to be used in preference to any
other main()s from external libraries,
just add the option -lHSrts before any
other libraries on the command line.
If you are using a Haskell “package”
(see Section 4.10), don't forget to add the
relevant -package option when linking the
program too: it will cause the appropriate libraries to be
linked in with the program. Forgetting the
-package option will likely result in
several pages of link errors.
On Darwin/MacOS X only, link in the framework name.
This option corresponds to the -framework option for Apple's Linker.
Please note that frameworks and packages are two different things - frameworks don't
contain any haskell code. Rather, they are Apple's way of packaging shared libraries.
To link to Apple's “Carbon” API, for example, you'd use
Where to find user-supplied libraries…
Prepend the directory dir to
the library directories path.
On Darwin/MacOS X only, prepend the directory dir to
the framework directories path. This option corresponds to the -F
option for Apple's Linker (-F already means something else for GHC).
Tell the linker to split the single object file that
would normally be generated into multiple object files,
one per top-level Haskell function or type in the module.
We use this feature for building GHC's libraries libraries
(warning: don't use it unless you know what you're
Tell the linker to avoid shared Haskell libraries,
if possible. This is the default.
Tell the linker to use shared Haskell libraries, if
available (this option is only supported on Windows at the
moment, and also note that your distribution of GHC may
not have been supplied with shared libraries).
In the event you want to include ghc-compiled code
as part of another (non-Haskell) program, the RTS will not
be supplying its definition of main()
at link-time, you will have to. To signal that to the
driver script when linking, use
Notice that since the command-line passed to the
linker is rather involved, you probably want to use
ghc to do the final link of your
`mixed-language' application. This is not a requirement
though, just try linking once with -v on
to see what options the driver passes through to the