Problems with main in a lib*.a. Is that a bug?

Nicolas Oury
Wed, 11 Dec 2002 18:47:37 +0100

Ok, I have made a "ghc -v"and see the problem :

* on OS X, a SDL program must have a main function supplied by a lib : 
* This is achieved by adding -lSDLmain at the command line.

* libHSrts.a supply a main. My program is linked against this lib by a 

ld is called by ghc with args :
[...] lHSrts [...] -lSDLmain [...]

mostly, I think, because S is greater than H. (-l args are in 
alphabetical order)

But, after linking the object, ld seek for a main function. And find 
first the main function  in libHSrts.a.

And the main needed by SDL is not used. And my test program crashes.

In fact, it would be better to really link with libHSrts.a at last 
(e.g. after all other -l args).
and not only after objetcs and mixed with other -l args.


>> I am building a SDL binding on MacOS X (but the same problem should
>> appears on Windows). It defines it's own main function in a
>> libSDLmain.a.
>> But I can't get ghc not to generate a main when linking with
>> -lSDLmain,
>> which is the option that is indicated to get the main function that
>> make SDL usable.
>> when I link write :
>> ghc -o test Main.hs libSDLmain.a , ghc doesn't generate a main as it
>> can see there is a main in libSDLmain. And my test programs works.
>> but when I write
>> ghc -o test Main.hs -lSDLmain, ghc creates its own main, and
>> it doesn't work.
> Could you give more details?  What is the error message?
> GHC doesn't generate main, there's a main function in libHSrts.a which
> is linked in last, so that you can override it with your own.  You
> should probably use -no-hs-main, too, otherwise the linker will require
> that Main.main exists in the Haskell code.
> Cheers,
> 	Simon
> _______________________________________________
> Glasgow-haskell-users mailing list