[Haskell-cafe] FFI link failing due to no main?

phil at beadling.co.uk phil at beadling.co.uk
Wed Aug 26 21:53:17 EDT 2009


Thanks for the reply!

I think this might be a Mac OS X issue.  I've stripped my rather  
longwinded example down to the simplest case (one Haskell source file  
to create a single shared library containing a single exported  
function) and this compiles (and ultimately runs) fine on Linux.  So  
I'm either doing something wrong which shouldn't really work on Linux  
(and I'm getting lucky!)... or something screwy is happening on Mac  
version:

This exports a single function which is then #included in CInterface.c  
to create a new pure-C wrapper to the function.

ghc -O2 -c HaskellFuncs.hs
ghc -O2 -no-hs-main --make -optl '-shared' CInterface.c  
HaskellFuncs_stub.o HaskellFuncs.o -o libCInterface.so

One Mac OS X I get the following error - but it works fine on Ubuntu.   
I'm using 6.10.4 on both machines:

Linking libCInterface.so ...
Undefined symbols:
   "_ZCMain_main_closure", referenced from:
       _ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o)
   "___stginit_ZCMain", referenced from:
       ___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o)
ld: symbol(s) not found

Could anyone comment if I'm doing anything wrong, or is this a case of  
unsupported functionality on (PPC/Leopard) Mac OS X?  Has anyone  
succeeded in getting a similar example to work on Mac OS X?

I notice on Linux it is still very temperamental, if I play around  
with the arguments even slightly I get the same error there.


Cheers,

Phil.

On 26 Aug 2009, at 06:51, Yusaku Hashimoto wrote:

> Missing -c option?
>
> And -v option to see what's going on.
>
> On Wed, Aug 26, 2009 at 10:37 AM, <phil at beadling.co.uk> wrote:
>> Hi,
>>
>> After creating my stub objects etc using GHC, I'm trying to create  
>> a library
>> with a C interface to some Haskell functions.  I'm explicitly  
>> passing in
>> -no-hs-main yet the linker still fails due to missing main?
>>
>> I'm sure I've had this working before with a slightly simpler  
>> example, but
>> can't work out what is wrong here.
>>
>> If I give it a main (to humor it - it's not a solution), then it  
>> links and
>> produces an executable - so it looks to me like I'm not telling the  
>> linker
>> what I want correctly?
>>
>> Any ideas?
>>
>> Cheers,
>>
>> Phil.
>>
>>
>> ghc -O2 --make -no-hs-main -package mtl   -package array -optl '- 
>> shared'
>> FFI/Octave/MyInterface.c FFI/Octave/OptionInterface_stub.o
>> FFI/Octave/OptionInterface.o ./FrameworkInterface.o ./Maths/Prime.o
>> ./MonteCarlo/DataStructures.o ./MonteCarlo/European.o
>> ./MonteCarlo/Framework.o ./MonteCarlo/Interface.o ./MonteCarlo/ 
>> Lookback.o
>> ./Normal/Acklam.o ./Normal/BoxMuller.o ./Normal/Framework.o
>> ./Normal/Interface.o ./Random/Framework.o ./Random/Halton.o
>> ./Random/Interface.o ./Random/Ranq1.o   -o FFI/Octave/ 
>> libMyInterface.so
>> Linking FFI/Octave/libMyInterface.so ...
>> Undefined symbols:
>>  "___stginit_ZCMain", referenced from:
>>      ___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o)
>>  "_ZCMain_main_closure", referenced from:
>>      _ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o)
>> ld: symbol(s) not found
>> collect2: ld returned 1 exit status
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>



More information about the Haskell-Cafe mailing list