1 <sect1 id="options-phases">
2 <title>Options related to a particular phase</title>
4 <sect2 id="replacing-phases">
5 <title>Replacing the program for one or more phases</title>
6 <indexterm><primary>phases, changing</primary></indexterm>
8 <para>You may specify that a different program be used for one
9 of the phases of the compilation system, in place of whatever
10 the <command>ghc</command> has wired into it. For example, you
11 might want to try a different assembler. The following options
12 allow you to change the external program used for a given
13 compilation phase:</para>
17 <term><option>-pgmL</option> <replaceable>cmd</replaceable></term>
18 <indexterm><primary><option>-pgmL</option></primary>
21 <para>Use <replaceable>cmd</replaceable> as the literate
27 <term><option>-pgmP</option> <replaceable>cmd</replaceable></term>
28 <indexterm><primary><option>-pgmP</option></primary>
31 <para>Use <replaceable>cmd</replaceable> as the C
32 pre-processor (with <option>-cpp</option> only).</para>
37 <term><option>-pgmc</option> <replaceable>cmd</replaceable></term>
38 <indexterm><primary><option>-pgmc</option></primary>
41 <para>Use <replaceable>cmd</replaceable> as the C
47 <term><option>-pgma</option> <replaceable>cmd</replaceable></term>
48 <indexterm><primary><option>-pgma</option></primary>
51 <para>Use <replaceable>cmd</replaceable> as the
57 <term><option>-pgml</option> <replaceable>cmd</replaceable></term>
58 <indexterm><primary><option>-pgml</option></primary>
61 <para>Use <replaceable>cmd</replaceable> as the
67 <term><option>-pgmdll</option> <replaceable>cmd</replaceable></term>
68 <indexterm><primary><option>-pgmdll</option></primary>
71 <para>Use <replaceable>cmd</replaceable> as the DLL
77 <term><option>-pgmdep</option> <replaceable>cmd</replaceable></term>
78 <indexterm><primary><option>-pgmdep</option></primary>
81 <para>Use <replaceable>cmd</replaceable> as the dependency
87 <term><option>-pgmF</option> <replaceable>cmd</replaceable></term>
88 <indexterm><primary><option>-pgmF</option></primary>
91 <para>Use <replaceable>cmd</replaceable> as the
92 pre-processor (with <option>-F</option> only).</para>
99 <sect2 id="forcing-options-through">
100 <title>Forcing options to a particular phase</title>
101 <indexterm><primary>forcing GHC-phase options</primary></indexterm>
103 <para>Options can be forced through to a particlar compilation
104 phase, using the following flags:</para>
108 <term><option>-optL</option> <replaceable>option</replaceable></term>
109 <indexterm><primary><option>-optL</option></primary>
112 <para>Pass <replaceable>option</replaceable> to the
113 literate pre-processor</para>
117 <term><option>-optP</option> <replaceable>option</replaceable></term>
118 <indexterm><primary><option>-optP</option></primary>
121 <para>Pass <replaceable>option</replaceable> to CPP (makes
122 sense only if <option>-cpp</option> is also on).</para>
126 <term><option>-optF</option> <replaceable>option</replaceable></term>
127 <indexterm><primary><option>-optF</option></primary>
130 <para>Pass <replaceable>option</replaceable> to the
131 custom pre-processor (see <xref linkend="pre-processor"/>).</para>
135 <term><option>-optc</option> <replaceable>option</replaceable></term>
136 <indexterm><primary><option>-optc</option></primary>
139 <para>Pass <replaceable>option</replaceable> to the C compiler.</para>
143 <term><option>-opta</option> <replaceable>option</replaceable></term>
144 <indexterm><primary><option>-opta</option></primary>
147 <para>Pass <replaceable>option</replaceable> to the assembler.</para>
151 <term><option>-optl</option> <replaceable>option</replaceable></term>
152 <indexterm><primary><option>-optl</option></primary>
155 <para>Pass <replaceable>option</replaceable> to the linker.</para>
159 <term><option>-optdll</option> <replaceable>option</replaceable></term>
160 <indexterm><primary><option>-optdll</option></primary>
163 <para>Pass <replaceable>option</replaceable> to the DLL generator.</para>
167 <term><option>-optdep</option> <replaceable>option</replaceable></term>
168 <indexterm><primary><option>-optdep</option></primary>
171 <para>Pass <replaceable>option</replaceable> to the
172 dependency generator.</para>
177 <para>So, for example, to force an <option>-Ewurble</option>
178 option to the assembler, you would tell the driver
179 <option>-opta-Ewurble</option> (the dash before the E is
182 <para>GHC is itself a Haskell program, so if you need to pass
183 options directly to GHC's runtime system you can enclose them in
184 <literal>+RTS ... -RTS</literal> (see <xref
185 linkend="runtime-control"/>).</para>
189 <sect2 id="c-pre-processor">
190 <title>Options affecting the C pre-processor</title>
192 <indexterm><primary>pre-processing: cpp</primary></indexterm>
193 <indexterm><primary>C pre-processor options</primary></indexterm>
194 <indexterm><primary>cpp, pre-processing with</primary></indexterm>
199 <term><option>-cpp</option></term>
200 <indexterm><primary><option>-cpp</option></primary></indexterm>
202 <para>The C pre-processor <command>cpp</command> is run
203 over your Haskell code only if the <option>-cpp</option>
204 option <indexterm><primary>-cpp
205 option</primary></indexterm> is given. Unless you are
206 building a large system with significant doses of
207 conditional compilation, you really shouldn't need
213 <term><option>-D</option><replaceable>symbol</replaceable><optional>=<replaceable>value</replaceable></optional></term>
214 <indexterm><primary><option>-D</option></primary></indexterm>
216 <para>Define macro <replaceable>symbol</replaceable> in the
217 usual way. NB: does <emphasis>not</emphasis> affect
218 <option>-D</option> macros passed to the C compiler
219 when compiling via C! For those, use the
220 <option>-optc-Dfoo</option> hack… (see <xref
221 linkend="forcing-options-through"/>).</para>
226 <term><option>-U</option><replaceable>symbol</replaceable></term>
227 <indexterm><primary><option>-U</option></primary></indexterm>
229 <para> Undefine macro <replaceable>symbol</replaceable> in the
235 <term><option>-I</option><replaceable>dir</replaceable></term>
236 <indexterm><primary><option>-I</option></primary></indexterm>
238 <para> Specify a directory in which to look for
239 <literal>#include</literal> files, in the usual C
245 <para>The GHC driver pre-defines several macros when processing
246 Haskell source code (<filename>.hs</filename> or
247 <filename>.lhs</filename> files):</para>
252 <term><constant>__HASKELL98__</constant></term>
253 <indexterm><primary><literal>__HASKELL98__</literal></primary></indexterm>
255 <para>If defined, this means that GHC supports the
256 language defined by the Haskell 98 report.</para>
261 <term><constant>__HASKELL__=98</constant></term>
262 <indexterm><primary><constant>__HASKELL__=98</constant></primary></indexterm>
264 <para>In GHC 4.04 and later, the
265 <constant>__HASKELL__</constant>
266 macro is defined as having the value
267 <constant>98</constant>.</para>
272 <term><constant>__HASKELL1__</constant></term>
273 <indexterm><primary><constant>__HASKELL1__
274 </constant></primary></indexterm>
276 <para>If defined to <replaceable>n</replaceable>, that
277 means GHC supports the Haskell language defined in the
278 Haskell report version <emphasis>1.n</emphasis>.
279 Currently 5. This macro is deprecated, and will probably
280 disappear in future versions.</para>
285 <term><constant>__GLASGOW_HASKELL__</constant></term>
286 <indexterm><primary><constant>__GLASGOW_HASKELL__</constant></primary></indexterm>
288 <para>For version <replaceable>n</replaceable> of the GHC
289 system, this will be <literal>#define</literal>d to
290 <replaceable>100n</replaceable>. For example, for version
291 5.00, it is 500.</para>
294 <constant>__GLASGOW_HASKELL__</constant>
295 will be undefined in all other implementations that
296 support C-style pre-processing.</para>
298 <para>(For reference: the comparable symbols for other
300 <constant>__HUGS__</constant>
302 <constant>__NHC__</constant>
304 <constant>__HBC__</constant>
305 for Chalmers.)</para>
307 <para>NB. This macro is set when pre-processing both
308 Haskell source and C source, including the C source
309 generated from a Haskell module
310 (i.e. <filename>.hs</filename>, <filename>.lhs</filename>,
311 <filename>.c</filename> and <filename>.hc</filename>
317 <term><constant>__CONCURRENT_HASKELL__</constant></term>
318 <indexterm><primary><constant>__CONCURRENT_HASKELL__</constant></primary></indexterm>
320 <para>This symbol is defined when pre-processing Haskell
321 (input) and pre-processing C (GHC output). Since GHC from
322 verion 4.00 now supports concurrent haskell by default,
323 this symbol is always defined.</para>
328 <term><constant>__PARALLEL_HASKELL__</constant></term>
329 <indexterm><primary><constant>__PARALLEL_HASKELL__</constant></primary></indexterm>
331 <para>Only defined when <option>-parallel</option> is in
332 use! This symbol is defined when pre-processing Haskell
333 (input) and pre-processing C (GHC output).</para>
338 <sect3 id="cpp-string-gaps">
339 <title>CPP and string gaps</title>
341 <para>A small word of warning: <option>-cpp</option> is not
342 friendly to “string gaps”.<indexterm><primary>-cpp
343 vs string gaps</primary></indexterm><indexterm><primary>string
344 gaps vs -cpp</primary></indexterm>. In other words, strings
345 such as the following:</para>
353 <para>don't work with <option>-cpp</option>;
354 <filename>/usr/bin/cpp</filename> elides the backslash-newline
357 <para>However, it appears that if you add a space at the end
358 of the line, then <command>cpp</command> (at least GNU
359 <command>cpp</command> and possibly other
360 <command>cpp</command>s) leaves the backslash-space pairs
361 alone and the string gap works as expected.</para>
365 <sect2 id="pre-processor">
366 <title>Options affecting a Haskell pre-processor</title>
368 <indexterm><primary>pre-processing: custom</primary></indexterm>
369 <indexterm><primary>Pre-processor options</primary></indexterm>
373 <term><option>-F</option></term>
374 <indexterm><primary><option>-F</option></primary></indexterm>
376 <para>A custom pre-processor is run over your Haskell
377 source file only if the <option>-F</option> option
378 <indexterm><primary>-F</primary></indexterm> is
381 <para>Running a custom pre-processor at compile-time is in
382 some settings appropriate and useful. The
383 <option>-F</option> option lets you run a pre-processor as
384 part of the overall GHC compilation pipeline, which has
385 the advantage over running a Haskell pre-processor
386 separately in that it works in interpreted mode and you
387 can continue to take reap the benefits of GHC's
388 recompilation checker.</para>
390 <para>The pre-processor is run just before the Haskell
391 compiler proper processes the Haskell input, but after the
392 literate markup has been stripped away and (possibly) the
393 C pre-processor has washed the Haskell input.</para>
396 <option>-pgmF <replaceable>cmd</replaceable></option>
397 to select the program to use as the preprocessor. When
398 invoked, the <replaceable>cmd</replaceable> pre-processor
399 is given at least three arguments on its command-line: the
400 first argument is the name of the original source file,
401 the second is the name of the file holding the input, and
402 the third is the name of the file where
403 <replaceable>cmd</replaceable> should write its output
406 <para>Additional arguments to the pre-processor can be
407 passed in using the <option>-optF</option> option. These
408 are fed to <replaceable>cmd</replaceable> on the command
409 line after the three standard input and output
416 <sect2 id="options-C-compiler">
417 <title>Options affecting the C compiler (if applicable)</title>
419 <indexterm><primary>include-file options</primary></indexterm>
420 <indexterm><primary>C compiler options</primary></indexterm>
421 <indexterm><primary>GCC options</primary></indexterm>
423 <para>If you are compiling with lots of foreign calls, you may
424 need to tell the C compiler about some
425 <literal>#include</literal> files. There is no real pretty
426 way to do this, but you can use this hack from the
430 % ghc -c '-#include <X/Xlib.h>' Xstuff.lhs
435 <sect2 id="options-codegen">
436 <title>Options affecting code generation</title>
440 <term><option>-fasm</option></term>
441 <indexterm><primary><option>-fasm</option></primary></indexterm>
443 <para>Use GHC's native code generator rather than
444 compiling via C. This will compile faster (up to twice as
445 fast), but may produce code that is slightly slower than
446 compiling via C. <option>-fasm</option> is the default
447 when optimisation is off (see <xref
448 linkend="options-optimise"/>).</para>
453 <term><option>-fvia-C</option></term>
454 <indexterm><primary><option>-fvia-C</option></primary>
457 <para>Compile via C instead of using the native code
458 generator. This is default for optimised compilations,
459 and on architectures for which GHC doesn't have a native
460 code generator.</para>
465 <term><option>-fno-code</option></term>
466 <indexterm><primary><option>-fno-code</option></primary>
469 <para>Omit code generation (and all later phases)
470 altogether. Might be of some use if you just want to see
471 dumps of the intermediate compilation phases.</para>
477 <sect2 id="options-linker">
478 <title>Options affecting linking</title>
480 <indexterm><primary>linker options</primary></indexterm>
481 <indexterm><primary>ld options</primary></indexterm>
484 <para>GHC has to link your code with various libraries, possibly
485 including: user-supplied, GHC-supplied, and system-supplied
486 (<option>-lm</option> math library, for example).</para>
491 <term><option>-l</option><replaceable>lib</replaceable></term>
492 <indexterm><primary><option>-l</option></primary></indexterm>
494 <para>Link in the <replaceable>lib</replaceable> library.
495 On Unix systems, this will be in a file called
496 <filename>lib<replaceable>lib</replaceable>.a</filename>
498 <filename>lib<replaceable>lib</replaceable>.so</filename>
499 which resides somewhere on the library directories path.</para>
501 <para>Because of the sad state of most UNIX linkers, the
502 order of such options does matter. If library
503 <replaceable>foo</replaceable> requires library
504 <replaceable>bar</replaceable>, then in general
505 <option>-l</option><replaceable>foo</replaceable> should
506 come <emphasis>before</emphasis>
507 <option>-l</option><replaceable>bar</replaceable> on the
510 <para>There's one other gotcha to bear in mind when using
511 external libraries: if the library contains a
512 <literal>main()</literal> function, then this will be
513 linked in preference to GHC's own
514 <literal>main()</literal> function
515 (eg. <literal>libf2c</literal> and <literal>libl</literal>
516 have their own <literal>main()</literal>s). This is
517 because GHC's <literal>main()</literal> comes from the
518 <literal>HSrts</literal> library, which is normally
519 included <emphasis>after</emphasis> all the other
520 libraries on the linker's command line. To force GHC's
521 <literal>main()</literal> to be used in preference to any
522 other <literal>main()</literal>s from external libraries,
523 just add the option <option>-lHSrts</option> before any
524 other libraries on the command line.</para>
529 <term><option>-no-link</option></term>
531 <primary><option>-no-link</option></primary>
534 <para>Omit the link step. This flag can be useful if you
535 want to avoid linking in <option>--make</option> mode,
536 where linking is normally done automatically if the program
537 contains a <literal>Main</literal> module.</para>
542 <term><option>-package</option> <replaceable>name</replaceable></term>
543 <indexterm><primary><option>-package</option></primary></indexterm>
545 <para>If you are using a Haskell “package”
546 (see <xref linkend="packages"/>), don't forget to add the
547 relevant <option>-package</option> option when linking the
548 program too: it will cause the appropriate libraries to be
549 linked in with the program. Forgetting the
550 <option>-package</option> option will likely result in
551 several pages of link errors.</para>
556 <term><option>-framework</option> <replaceable>name</replaceable></term>
557 <indexterm><primary><option>-framework</option></primary></indexterm>
559 <para>On Darwin/MacOS X only, link in the framework <replaceable>name</replaceable>.
560 This option corresponds to the <option>-framework</option> option for Apple's Linker.
561 Please note that frameworks and packages are two different things - frameworks don't
562 contain any haskell code. Rather, they are Apple's way of packaging shared libraries.
563 To link to Apple's “Carbon” API, for example, you'd use
564 <option>-framework Carbon</option>.
570 <term><option>-L</option><replaceable>dir</replaceable></term>
571 <indexterm><primary><option>-L</option></primary></indexterm>
573 <para>Where to find user-supplied libraries…
574 Prepend the directory <replaceable>dir</replaceable> to
575 the library directories path.</para>
580 <term><option>-framework-path</option><replaceable>dir</replaceable></term>
581 <indexterm><primary><option>-framework-path</option></primary></indexterm>
583 <para>On Darwin/MacOS X only, prepend the directory <replaceable>dir</replaceable> to
584 the framework directories path. This option corresponds to the <option>-F</option>
585 option for Apple's Linker (<option>-F</option> already means something else for GHC).</para>
590 <term><option>-split-objs</option></term>
591 <indexterm><primary><option>-split-objs</option></primary></indexterm>
593 <para>Tell the linker to split the single object file that
594 would normally be generated into multiple object files,
595 one per top-level Haskell function or type in the module.
596 We use this feature for building GHC's libraries libraries
597 (warning: don't use it unless you know what you're
603 <term><option>-static</option></term>
604 <indexterm><primary><option>-static</option></primary></indexterm>
606 <para>Tell the linker to avoid shared Haskell libraries,
607 if possible. This is the default.</para>
612 <term><option>-dynamic</option></term>
613 <indexterm><primary><option>-dynamic</option></primary></indexterm>
615 <para>Tell the linker to use shared Haskell libraries, if
616 available (this option is only supported on Windows at the
617 moment, and also note that your distribution of GHC may
618 not have been supplied with shared libraries).</para>
623 <term><option>-main-is <replaceable>thing</replaceable></option></term>
624 <indexterm><primary><option>-main-is</option></primary></indexterm>
625 <indexterm><primary>specifying your own main function</primary></indexterm>
627 <para> The normal rule in Haskell is that your program must supply a <literal>main</literal>
628 function in module <literal>Main</literal>. When testing, it is often convenient
629 to change which function is the "main" one, and the <option>-main-is</option> flag
630 allows you to do so. The <replaceable>thing</replaceable> can be one of:
632 <listitem><para>A lower-case identifier <literal>foo</literal>. GHC assumes that the main function is <literal>Main.foo</literal>.</para></listitem>
633 <listitem><para>An module name <literal>A</literal>. GHC assumes that the main function is <literal>A.main</literal>.</para></listitem>
634 <listitem><para>An qualified name <literal>A.foo</literal>. GHC assumes that the main function is <literal>A.foo</literal>.</para></listitem>
636 Strictly speaking, <option>-main-is</option> is not a link-phase flag at all; it has no effect on the link step.
637 The flag must be specified when compiling the module containing the specified main function (e.g. module <literal>A</literal>
638 in the latter two items above. It has no effect for other modules (and hence can safely be given to <literal>ghc --make</literal>).
644 <term><option>-no-hs-main</option></term>
645 <indexterm><primary><option>-no-hs-main</option></primary></indexterm>
646 <indexterm><primary>linking Haskell libraries with foreign code</primary></indexterm>
648 <para>In the event you want to include ghc-compiled code
649 as part of another (non-Haskell) program, the RTS will not
650 be supplying its definition of <function>main()</function>
651 at link-time, you will have to. To signal that to the
652 compiler when linking, use
653 <option>-no-hs-main</option>. See also <xref linkend="using-own-main"/>.</para>
655 <para>Notice that since the command-line passed to the
656 linker is rather involved, you probably want to use
657 <command>ghc</command> to do the final link of your
658 `mixed-language' application. This is not a requirement
659 though, just try linking once with <option>-v</option> on
660 to see what options the driver passes through to the
663 <para>The <option>-no-hs-main</option> flag can also be
664 used to persuade the compiler to do the link step in
665 <option>--make</option> mode when there is no Haskell
666 <literal>Main</literal> module present (normally the
667 compiler will not attempt linking when there is no
668 <literal>Main</literal>).</para>
673 <term><option>-debug</option></term>
674 <indexterm><primary><option>-debug</option></primary>
677 <para>Link the program with a debugging version of the
678 runtime system. The debugging runtime turns on numerous
679 assertions and sanity checks, and provides extra options
680 for producing debugging output at runtime (run the program
681 with <literal>+RTS -?</literal> to see a list).</para>
686 <term><option>-threaded</option></term>
687 <indexterm><primary><option>-threaded</option></primary>
690 <para>Link the program with the "threaded" runtime system.
691 This version of the runtime is designed to be used in
692 programs that use multiple operating-system threads. It
693 supports calls to foreign-exported functions from multiple
694 OS threads. Calls to foreign functions are made using the
695 same OS thread that created the Haskell thread (if it was
696 created by a call-in), or an arbitrary OS thread otherwise
697 (if the Haskell thread was created by
698 <literal>forkIO</literal>).</para>
700 <para>More details on the use of "bound threads" in the
701 threaded runtime can be found in the <ulink
702 url="../libraries/base/Control.Concurrent.html"><literal>Control.Concurrent</literal></ulink> module.</para>
704 <para>The threaded RTS does <emphasis>not</emphasis>
705 support using multiple CPUs to speed up execution of a
706 multi-threaded Haskell program. The GHC runtime platform
707 is still single-threaded, but using the
708 <option>-threaded</option> option it can be used safely in
709 a multi-threaded environment.</para>
719 ;;; Local Variables: ***
721 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***