Ticket #5825 (closed bug: invalid)

Opened 4 months ago

Last modified 4 months ago

GHC can't build C program that uses exported Haskell function

Reported by: shelarcy Owned by:
Priority: normal Milestone:
Component: Compiler (FFI) Version: 7.4.1-rc2
Keywords: Cc: shelarcy@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

GHC 7.4.1 RC2 can't build foreign export example on Mac OS X and Windows. (I used first version of main().)

$ ghc Foo.hs -c
$ ghc Foo.o import.c -o exportHaskell
import.c: In function ‘main’:

import.c:17:0:
     warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘HsInt’

import.c:17:0:
     warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘HsInt’
ld: duplicate symbol _main in /var/folders/zs/bsr11y_x3d76ssg4bl_kx7nm0000gn/T/ghc61891_0/ghc61891_0.o and import.o for architecture x86_64
collect2: ld returned 1 exit status

I can build this program with (Haskell Platform 2011.4.0.0's) GHC 7.0.4 and 7.2.2. So, I don't know why GHC 7.4.1 RC 2 can't build program.

$ ghc-7.0.4 Foo.hs -c
$ ghc-7.0.4 Foo.o import.c Foo_stub.c -o exportHaskell
import.c: In function ‘main’:

import.c:17:0:
     warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘HsInt’

import.c:17:0:
     warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘HsInt’
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame
$ ./exportHaskell 
2500
2500
2500
2500
2500
$ ghc-7.2.2 Foo.hs -c
$ ghc-7.2.2 Foo.o import.c -o exportHaskell
import.c: In function ‘main’:

import.c:17:0:
     warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘HsInt’

import.c:17:0:
     warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘HsInt’
ld: warning: could not create compact unwind for .LFB3: non-standard register 5 being saved in prolog
ld: warning: text reloc in _main to cstring
(snip)
ld: warning: text reloc in _cOp_str to _stg_ap_pppppp_info
$ ./exportHaskell
2500
2500
2500
2500
2500

Change History

Changed 4 months ago by igloo

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to invalid

You need to add -no-hs-main to the second command, or you will end up with 2 main functions in the executable: The one in your C file, and the one from GHC's RTS (which executes Main.main).

Note: See TracTickets for help on using tickets.