Opened 6 years ago

Closed 6 years ago

#5428 closed bug (worksforme)

Creating executable in OS X Lion

Reported by: sweirich Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.3
Keywords: linking main executable Cc:
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonmar)

Can't seem to create an executable when the module is not named "Main"

For example:

sweirich$ ghc --make lec1.lhs -o hello -main-is Lec1
Linking hello ...
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame
Undefined symbols for architecture x86_64:
  "_ZCMain_main_closure", referenced from:
      _main in libHSrtsmain.a(Main.o)
  "___stginit_ZCMain", referenced from:
      _main in libHSrtsmain.a(Main.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

on the other hand, if I rename the file 'Main.lhs' and edit the module name to 'Main' then everything works correctly.

sweirich$ ghc --make Main.lhs
[1 of 1] Compiling Main             ( Main.lhs, Main.o )
Linking Main ...
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in ___gmpn_modexact_1c_odd from /Library/Frameworks/GHC.framework/Versions/7.0.3-x86_64/usr/lib/ghc-7.0.3/integer-gmp- To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
sweirich$ ./Main
Hello World! 

Change History (5)

comment:1 Changed 6 years ago by simonmar

Description: modified (diff)

It looks like you had already compiled lec1.lhs without the -main-is option, and then added the -main-is option later. Could that be the case? Could you try from scratch, deleting all the .o and .hi files first?

comment:2 Changed 6 years ago by igloo

Status: newinfoneeded

comment:3 Changed 6 years ago by mcandre

The same thing happens for me in Lion with Xcode 4.1 and no intermediate files.

comment:4 Changed 6 years ago by judahj

For what it's worth, this works fine for me on Lion with Xcode 4.1 (64-bit), using both ghc-7.2.1 and ghc-7.0.3.

I made a file Standalone.hs:

module Standalone where
main = putStrLn "Hello"

and ran

ghc Standalone.hs -main-is Standalone

which produced an executable named "Standalone". Does that work for you?

comment:5 Changed 6 years ago by mcandre

Resolution: worksforme
Status: infoneededclosed

Confirmed: They're just warnings.

Warnings shoo, shoo!

Note: See TracTickets for help on using tickets.