Opened 5 years ago

Closed 5 years ago

#5574 closed bug (invalid)

undefined reference to `ZCMain_main_closure' and undefined reference to `__stginit_ZCMain' collect2:

Reported by: francisco Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.3
Keywords: Cc: azufaifa@…
Operating System: Linux Architecture: x86
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Environment of work

Ubuntu 11.10

$ uname -a Linux fmgo-HP 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011 i686 i686 i386 GNU/Linux

$ ghci GHCi, version 7.0.3

$gcc -v .... gcc versión 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

The problem

I composed the file "TorresHanoiMenu.hs" that import and uses "TorresHanoi.hs" (attached in a .zip file)

GHCi produces la following dialog

$ ghci TorresHanoiMenu.hs [1 of 2] Compiling TorresHanoi ( TorresHanoi.hs, interpreted ) [2 of 2] Compiling TorresHanoiMenu ( TorresHanoiMenu.hs, interpreted ) Ok, modules loaded: TorresHanoiMenu, TorresHanoi. *TorresHanoiMenu>

and the program works "fine" (execpt for the definition of "mover", see ticket #5572).

Well, now I wish to produce an executable program from TorresHanoiMenu.hs, therefore I make

$ ghc --make TorresHanoiMenu.hs

At this moment the files .o and .hi are generated but not so the executable. I deleted the files .o and .hi. Next I make

$ ghc -c -O TorresHanoi.hs TorresHanoiMenu.hs

and the files .o and .hi are newly generated. Then I make

$ ghc -o menu -O TorresHanoi.o TorresHanoiMenu.o

and the generated message of error is:

/usr/lib/ghc-7.0.3/libHSrtsmain.a(Main.o): In function `main': (.text.startup+0x10): undefined reference to `ZCMain_main_closure' /usr/lib/ghc-7.0.3/libHSrtsmain.a(Main.o): In function `main': (.text.startup+0x18): undefined reference to `stginit_ZCMain' collect2: ld devolvió el estado de salida 1

Of course there is no executable "menu" file.

The problem or bug exists in: GHCi ver. 6.10.4 and GHCi ver. 6.12.3

Attachments (1) (1.6 KB) - added by francisco 5 years ago.

Download all attachments as: .zip

Change History (3)

Changed 5 years ago by francisco

Attachment: added

comment:1 Changed 5 years ago by francisco

Summary: undefined reference to `ZCMain_main_closure' and undefined reference to `ZCMain_main_closure'undefined reference to `ZCMain_main_closure' and undefined reference to `__stginit_ZCMain' collect2:

comment:2 Changed 5 years ago by

Resolution: invalid
Status: newclosed

The problem is

module TorresHanoiMenu where

To produce an executable, there must be an entry point, for which special code has to be generated so that it can be called from outside Haskell. By default, that entry point is the function main in module Main. If there is no module Main, ghc doesn't create an executable. If there is a Main module, but no function main in that, ghc (--make) aborts the compilation.

Unless the function to use as entry point has been explicitly specified via the -main-is option.
You can pass a function name (foo), a module name (Bar) or a qualified function name (Baz.boing) as an argument to that option, making the entry point, Bar.main resp. Baz.boing.

In your case, you could a) rename the module to Main b) compile with either of

$ ghc -O --make -o menu -main-is TorresHanoiMenu.main TorresHanoiMenu.hs
$ ghc -O --make -o menu -main-is TorresHanoiMenu TorresHanoiMenu.hs

(for ghc 7.0.1 or later, the --make isn't necessary anymore).

Since ghc didn't create any special code for an entry point, the linker couldn't find it, hence the undefined references.

Note: See TracTickets for help on using tickets.