简体   繁体   中英

Compiling separate modules in GHC

I am really struggling to do what must be a very simple thing in GHC: I have a program that works and compiles fine, but when I split it so that part of the code is in a separate module I can't get it to work. The separate module is called FICutilities

ghc -o FICutilities FICutilities.hs C:\\ghc\\ghc-6.10.1/libHSrts.a(Main.o):Main.c:(.text+0x7): undefined reference to __stginit_ZCMain' C:\\ghc\\ghc-6.10.1/libHSrts.a(Main.o):Main.c:(.text+0x36): undefined reference to ZCMain_main_closure' collect2: ld returned 1 exit status

As far as I can see this is because there is no main function, but I don't want one in this module. I am using version 6.10.1 because I can't get more recent ones to work.

Please can someone help?! Thanks, Clare.

Just add -c switch.

However, you shouldn't build modules yourself: the recommended way of building is by using Cabal.

Other ways are:

  1. ghc --make Main.hs builds main and its dependencies recompiling as necessary.
  2. ghc -M Main.hs parses the imports recursively and generates a makefile with dependencies so you can use this information in your build system.

Neither http://www.haskell.org/ghc/docs/latest/html/users_guide/modes.html nor http://www.haskell.org/ghc/docs/latest/html/users_guide/modes.html#make-mode say --make is deprecated. It's not recommended if Cabal is a viable option. A big project is a pain to maintain without Cabal. Some tools in Haskell toolchain have plugins for Cabal (eg UUAGC attribute grammar preprocessor and others).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM