
Is there a way to compile a Haskell script with a different module name than Main? #!/usr/bin/env runhaskell module ScriptedMain where meaningOfLife :: Int meaningOfLife = 42 main :: IO () main = putStrLn $ "Main: The meaning of life is " ++ show meaningOfLife $ ghc -o scriptedmain scriptedmain.hs Undefined symbols: "_ZCMain_main_closure", referenced from: _ZCMain_main_closure$non_lazy_ptr in libHSrtsmain.a(Main.o) (maybe you meant: _ZCMain_main_closure$non_lazy_ptr) "___stginit_ZCMain", referenced from: ___stginit_ZCMain$non_lazy_ptr in libHSrtsmain.a(Main.o) (maybe you meant: ___stginit_ZCMain$non_lazy_ptr) ld: symbol(s) not found collect2: ld returned 1 exit status Cheers, Andrew Pennebaker www.yellosoft.us

On Sunday 06 March 2011 23:32:43, Andrew Pennebaker wrote:
Is there a way to compile a Haskell script with a different module name than Main?
$ ghc -main-is ScriptedMain --make ScriptedMain The -main-is flag tells GHC what to regard as Main.main. Give it a module name (Foo) to say main is Foo.main, a function name (bar) to tell it main is Main.bar or a quailfied function name (Foo.bar) to tell it main is function bar in module Foo.

I got -main-is to work with a single Haskell file, but it seems to have trouble with multiple files. $ cat scriptedmain.hs #!/usr/bin/env runhaskell module ScriptedMain where meaningOfLife :: Int meaningOfLife = 42 main :: IO () main = putStrLn $ "Main: The meaning of life is " ++ show meaningOfLife $ cat test.hs #!/usr/bin/env runhaskell module Test where import ScriptedMain hiding (main) main :: IO () main = putStrLn $ "Test: The meaning of life is " ++ show meaningOfLife $ ghc -o scriptedmain -main-is ScriptedMain scriptedmain.hs $ ./scriptedmain Main: The meaning of life is 42 $ ghc -o test -main-is Test.main test.hs scriptedmain.hs compilation IS NOT required ld: duplicate symbol _ZCMain_main_info in scriptedmain.o and test.o collect2: ld returned 1 exit status Cheers, Andrew Pennebaker www.yellosoft.us On Sun, Mar 6, 2011 at 5:54 PM, Daniel Fischer < daniel.is.fischer@googlemail.com> wrote:
On Sunday 06 March 2011 23:32:43, Andrew Pennebaker wrote:
Is there a way to compile a Haskell script with a different module name than Main?
$ ghc -main-is ScriptedMain --make ScriptedMain
The -main-is flag tells GHC what to regard as Main.main. Give it a module name (Foo) to say main is Foo.main, a function name (bar) to tell it main is Main.bar or a quailfied function name (Foo.bar) to tell it main is function bar in module Foo.

On Monday 07 March 2011 00:03:26, Andrew Pennebaker wrote:
$ ghc -o scriptedmain -main-is ScriptedMain scriptedmain.hs $ ./scriptedmain Main: The meaning of life is 42 $ ghc -o test -main-is Test.main test.hs scriptedmain.hs compilation IS NOT required
You have to recompile, I'm afraid. GHC generated the code for ScriptedMain.main as entry point 'main', then it generated the code for Test.main as entry point 'main', so there's two symbols for the entry point 'main', I don't think you can hide that from the linker. $ ghc -fforce-recomp -o test -main-is... That would of course be inconvenient if there's more than a small module to recompile, so it's a good idea to separate the 'main's from the code that really does stuff.
ld: duplicate symbol _ZCMain_main_info in scriptedmain.o and test.o collect2: ld returned 1 exit status
Cheers,
Andrew Pennebaker

It turns out you need to delete scriptedmain.o in order for test.hs to compile. Cheers, Andrew Pennebaker www.yellosoft.us On Sun, Mar 6, 2011 at 5:54 PM, Daniel Fischer < daniel.is.fischer@googlemail.com> wrote:
On Sunday 06 March 2011 23:32:43, Andrew Pennebaker wrote:
Is there a way to compile a Haskell script with a different module name than Main?
$ ghc -main-is ScriptedMain --make ScriptedMain
The -main-is flag tells GHC what to regard as Main.main. Give it a module name (Foo) to say main is Foo.main, a function name (bar) to tell it main is Main.bar or a quailfied function name (Foo.bar) to tell it main is function bar in module Foo.
participants (2)
-
Andrew Pennebaker
-
Daniel Fischer