Bulding a library for C users on OS X

View: New views
4 Messages — Rating Filter:   Alert me  

Bulding a library for C users on OS X

by Chris Eidhof :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey all,

I'm trying to call a Haskell function from C, on OS X. There's an  
excellent post [1] by Tomáš Janoušek that explains how to do this on  
Linux. However, on OS X, it's different. First of all, it looks like  
the -no-hs-main flag is ignored, because I get the following error:

 > ghc -O2 --make       -no-hs-main -optl '-shared' -optc '-
DMODULE=Test'       -o Test.so Test.hs module_init.c
 > [1 of 1] Compiling Main             ( Test.hs, Test.o )
 >
 > Test.hs:1:0: The function `main' is not defined in module `Main'

Second, I learned [2] that I have to pass in different flags on OS X,  
but unfortunately, GHC still wants me to have main. I'm probably doing  
something wrong here, is there anyone who can give me some pointers?  
(no pun intended).

I'm running GHC 6.10.2 on Leopard.

Thanks,
-chris

[1]: http://blog.haskell.cz/pivnik/building-a-shared-library-in-haskell/
[2]: http://www.mail-archive.com/haskell-cafe@.../msg51303.html_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Bulding a library for C users on OS X

by Manuel M T Chakravarty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Chris Eidhof:

> I'm trying to call a Haskell function from C, on OS X. There's an  
> excellent post [1] by Tomáš Janoušek that explains how to do this on  
> Linux. However, on OS X, it's different. First of all, it looks like  
> the -no-hs-main flag is ignored, because I get the following error:
>
> > ghc -O2 --make       -no-hs-main -optl '-shared' -optc '-
> DMODULE=Test'       -o Test.so Test.hs module_init.c
> > [1 of 1] Compiling Main             ( Test.hs, Test.o )
> >
> > Test.hs:1:0: The function `main' is not defined in module `Main'''

The flag -no-hs-main is a link-time flag that allows you to link  
without a main function, but you are getting a compile time error.  
It's as if you try to export main, but don't define it.

Have you had a look at http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#foreign-export-ghc 
  ?

Manuel

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Bulding a library for C users on OS X

by Chris Eidhof :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 2 nov 2009, at 03:30, Manuel M T Chakravarty wrote:

> Chris Eidhof:
>> I'm trying to call a Haskell function from C, on OS X. There's an  
>> excellent post [1] by Tomáš Janoušek that explains how to do this  
>> on Linux. However, on OS X, it's different. First of all, it looks  
>> like the -no-hs-main flag is ignored, because I get the following  
>> error:
>>
>> > ghc -O2 --make       -no-hs-main -optl '-shared' -optc '-
>> DMODULE=Test'       -o Test.so Test.hs module_init.c
>> > [1 of 1] Compiling Main             ( Test.hs, Test.o )
>> >
>> > Test.hs:1:0: The function `main' is not defined in module `Main'''
>
> The flag -no-hs-main is a link-time flag that allows you to link  
> without a main function, but you are getting a compile time error.  
> It's as if you try to export main, but don't define it.
>
> Have you had a look at http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#foreign-export-ghc 
>  ?


Interesting! I didn't see that section before, thanks a lot.

-chris

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

RE: Bulding a library for C users on OS X

by Simon Peyton-Jones :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There is some stuff on using the FFI under "Collaborative documentation"  at http://haskell.org/haskellwiki/GHC.  The FFI link takes you to http://haskell.org/haskellwiki/GHC/Using_the_FFI

It's called "collaborative" because it's When you solve your problem, can I urge you to update that page (its a  wiki) to embody what you  have learned?

Simon

| -----Original Message-----
| From: haskell-cafe-bounces@... [mailto:haskell-cafe-bounces@...] On
| Behalf Of Chris Eidhof
| Sent: 02 November 2009 10:22
| To: Manuel M T Chakravarty
| Cc: Haskell Cafe
| Subject: Re: [Haskell-cafe] Bulding a library for C users on OS X
|
| On 2 nov 2009, at 03:30, Manuel M T Chakravarty wrote:
|
| > Chris Eidhof:
| >> I'm trying to call a Haskell function from C, on OS X. There's an
| >> excellent post [1] by Tomáš Janoušek that explains how to do this
| >> on Linux. However, on OS X, it's different. First of all, it looks
| >> like the -no-hs-main flag is ignored, because I get the following
| >> error:
| >>
| >> > ghc -O2 --make       -no-hs-main -optl '-shared' -optc '-
| >> DMODULE=Test'       -o Test.so Test.hs module_init.c
| >> > [1 of 1] Compiling Main             ( Test.hs, Test.o )
| >> >
| >> > Test.hs:1:0: The function `main' is not defined in module `Main'''
| >
| > The flag -no-hs-main is a link-time flag that allows you to link
| > without a main function, but you are getting a compile time error.
| > It's as if you try to export main, but don't define it.
| >
| > Have you had a look at
| http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#foreign-export-
| ghc
| >  ?
|
|
| Interesting! I didn't see that section before, thanks a lot.
|
| -chris
|
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe@...
| http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe