13
votes

I'm very new to Haskell, and I've recently installed the platform with GHC. I decided to test it out by compiling a simple Hello world program: main = putStrLn "Hello, world"

Now, when I go into the command line (Windows 7), find the proper directory, and type in ghc hello.hs, it comes back with the following message: "[1 of 1] Compiling Main ( hello.hs, hello.o )". I understand that once it's done compiling, it should follow with "Linking hello.exe ...", but that never comes, and no .exe is produced.

Basically, is there any discernible reason why this would be happening? Is there a problem with the code, is there something I don't know about, or should I just try re-installing the Haskell Platform?

Thank you.

3
To be clear: are you concerned because it isn't producing hello.exe, or because it isn't displaying that bit of text? Does it actually produce the executable, and does that executable perform as instructed? - Julian Fondren
Sorry - it doesn't produce the .exe. So far as I can tell, nor does it produce the .o or .hi files. Where would GHC usually put these files once created, also? In the same directory as the .hs? - Stacky McBears
Yes, it is usually the same directory. If you have an older GHC, you may want to ghc --make hello.hs. What version of GHC do you have? ghc --version if you recently installed it should be 7.0.4 I think. I have 7.0.3 on Win7 and ghc hello.hs && hello.exe works just fine. - Dan Burton
Trying to compile the .hs from the command line is still not working, with the above recommendations (it is 7.0.4). However, it seems to compile just fine when using "Open with..." and selecting ghc. Everything's there, and the .exe runs as expected. Though I'm still kind of irked that it won't work in the command line in case I'd like to use options in the future, this should work fine for now. Thanks for your input everyone - Stacky McBears
I can compile my Hello.hs. *.hi, *.o and *.exe files appear, but when I try to run Hello.exe, cmd goes on forever, nothing happens... - Suspended

3 Answers

15
votes

I got ghc to link my program into an executable by removing module declaration from the start of the file.

1
votes

Has it produced an a.exe or a.out.exe or a.out file instead? If not, then maybe you can just link it yourself? ld -o hello.exe hello.o or whatever the link command is on your platform.

1
votes

I would use the --make option, as in ghc --make hello.hs. (You can actually leave out the file extension if you like.) This will automatically figure out what needs to be done, which packages if any need to be linked in, and generally do everything you'd expect.