2

I created a very simple program:

module CompileTest(main) where

main = putStrLn "Hello, World!"

When I try to compile it using ghc CompileTest.hs I get:

/usr/lib/ghc-6.12.1/libHSrtsmain.a(Main.o): In function `main':
(.text+0x10): undefined reference to `ZCMain_main_closure'
/usr/lib/ghc-6.12.1/libHSrtsmain.a(Main.o): In function `main':
(.text+0x18): undefined reference to `__stginit_ZCMain'

Does anyone know what this is? I'm not doing anything complicated. And it works fine in GHCi.

Xodarap
  • 11,581
  • 11
  • 56
  • 94
  • 2
    As an addition to Thomas' answer, with the `-main-is` flag, the `main` function need not be called `main`, you can use `ghc --make -main-is Foo.bar Foo.hs` to compile with the function `bar` in module `Foo` as entry point. – Daniel Fischer Mar 10 '12 at 16:35

1 Answers1

5

The main function must be in the Main module. That or use the -main-is GHC flag. Also, with GHC < 7 you need to use the compilation flag of --make.

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166