Jake McLaughlin
Jake McLaughlin

Reputation: 318

"module [...] is defined in multiple files" error from Haskell compilation

I am getting the following error when i compile with the -Wall option.

ghc -o -Wall polycake polycake.hs

When I don't use the option my code compiles fine and runs as expected. What does this mean?

<no location info>: error:
    module ‘main:Polycake’ is defined in multiple files: polycake.hs
                                                         polycake.hs

Upvotes: 3

Views: 1889

Answers (1)

sepp2k
sepp2k

Reputation: 370282

The -o option expects the output file name as the next argument - it does not care whether that argument starts with a dash or not. So -o -Wall sets the output file name to -Wall (and does not actually enable warnings).

So the two left over arguments are polycake and polycake.hs, which ghc interprets as input file names. When an input file name does not exist and does not already end with the .hs extension, ghc will try to add that extension. So ghc polycake polycake.hs will try to compile polycake.hs twice. This leads to your error.

PS: The output file name defaults to the input file name without the extension, so you don't need the -o option at all in this case.

Upvotes: 8

Related Questions