1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
4 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
5 <title>The GHC Commentary - Compiling and running the Main module</title>
8 <body BGCOLOR="FFFFFF">
9 <h1>Compiling and running the Main module</h1>
11 GHC allows you to determine which module contains the "main" function, and
12 what that function is called, via the <code>-fmain-is</code> flag. The trouble is
13 that the runtime system is fixed, so what symbol should it link to?
15 The current solution is this. Suppose the main function is <code>Foo.run</code>.
18 Then, when compiling module <code>Foo</code>, GHC adds an extra definition:
20 :Main.main = runIO Foo.run
22 Now the RTS can invoke <code>:Main.main</code> to start the program. (This extra
23 definition is inserted in TcRnDriver.checkMain.)
25 Before starting the program, though, the RTS also initialises the module tree
26 by calling <code>init_:Main</code>, so when compiling the main module (Foo in this case),
27 as well as generating <code>init_Foo</code> as usual, GHC also generates
29 init_zcMain() { init_Foo; }
31 This extra initialisation code is generated in CodeGen.mkModuleInit.