# Compiling and running the Main module

GHC allows you to determine which module contains the "main" function, and what that function is called, via the `-fmain-is` flag. The trouble is that the runtime system is fixed, so what symbol should it link to?

The current solution is this. Suppose the main function is `Foo.run`.

- Then, when compiling module `Foo`, GHC adds an extra definition:

        :Main.main = runIO Foo.run

  Now the RTS can invoke `:Main.main` to start the program. (This extra definition is inserted in TcRnDriver.checkMain.)

- Before starting the program, though, the RTS also initialises the module tree by calling `init_:Main`, so when compiling the main module (Foo in this case), as well as generating `init_Foo` as usual, GHC also generates

        init_zcMain() { init_Foo; }

  This extra initialisation code is generated in CodeGen.mkModuleInit.