简体   繁体   English

在GHC中编译单独的模块

[英]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. 我确实在做GHC中必须做的非常简单的事情:我有一个可以正常工作并且编译良好的程序,但是当我将其拆分以使部分代码位于单独的模块中时,我无法使它工作。 The separate module is called FICutilities 单独的模块称为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 ghc -o FICutilities FICutilities.hs C:\\ ghc \\ ghc-6.10.1 / libHSrts.a(Main.o):Main.c :(。text + 0x7):对__stginit_ZCMain' C:\\ghc\\ghc-6.10.1/libHSrts.a(Main.o):Main.c:(.text+0x36): 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的__stginit_ZCMain' C:\\ghc\\ghc-6.10.1/libHSrts.a(Main.o):Main.c:(.text+0x36): undefined reference to 'collect2:ld返回1退出状态

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. 我使用的版本是6.10.1,因为我无法使用更新的版本。

Please can someone help?! 请有人帮忙吗? Thanks, Clare. 谢谢克莱尔

Just add -c switch. 只需添加-c开关即可。

However, you shouldn't build modules yourself: the recommended way of building is by using Cabal. 但是,您不应该自己构建模块:建议的构建方法是使用Cabal。

Other ways are: 其他方式是:

  1. ghc --make Main.hs builds main and its dependencies recompiling as necessary. ghc --make Main.hs生成main并根据需要重新编译其依赖项。
  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. ghc -M Main.hs递归解析导入并生成具有相关性的makefile,因此您可以在构建系统中使用此信息。

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. http://www.haskell.org/ghc/docs/latest/html/users_guide/modes.htmlhttp://www.haskell.org/ghc/docs/latest/html/users_guide/modes.html#make都不-mode--make已过时。 It's not recommended if Cabal is a viable option. 如果Cabal是可行的选项,则不建议使用。 A big project is a pain to maintain without Cabal. 如果没有Cabal,一个大项目很难维护。 Some tools in Haskell toolchain have plugins for Cabal (eg UUAGC attribute grammar preprocessor and others). Haskell工具链中的某些工具具有Cabal插件(例如UUAGC属性语法预处理器等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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