gatoatigrado
gatoatigrado

Reputation: 16850

haskell -- how to create a binary from a non-Main module?

I often have situations where I leave main :: IO () functions in tests. I can run these fine with runghc, but sometimes I want to compile them (e.g. for running on another platform). Is there a way to do this? If I run, for example,

ghc --make Test.Haar

where Test/Haar.hs has a main method, then nothing happens, it just creates the .o file.

Upvotes: 9

Views: 256

Answers (2)

Daniel Fischer
Daniel Fischer

Reputation: 183873

Note, however, that after using -main-is Test.Haar, if you want to use the module as part of another programme, you have to recompile it without the -main-is, otherwise the linker will find two entry-points and throw an error.

Upvotes: 4

nponeccop
nponeccop

Reputation: 13677

ghc --make -main-is Test.Haar Test.Haar

Upvotes: 13

Related Questions