[jhc] dynamic library support?

Mark Wotton mwotton at gmail.com
Fri Aug 7 07:48:04 EDT 2009


On 06/08/2009, at 6:11 PM, John Meacham wrote:

> On Thu, Aug 06, 2009 at 05:22:06PM +1000, Mark Wotton wrote:
>> Is there a way to build dynamic libraries in jhc such they're  
>> linkable
>> and callable from a C driver?
>> I'm hoping to write a bridge between ruby and haskell, and GHC's  
>> dynamic
>> lib support seems a bit sketchy currently.
>
> If your interface is constrained to things expressible in the FFI  
> spec,
> then you can 'foreign export' whatever functions you like from haskell
> then compile the resulting C file into a shared library. I don't  
> have a
> specific option that does this automatically, but it should be easy to
> do by hand once you see the C file it produces. Let me know what  
> issues
> you run into, if we can come up with a generally useful 'recipe' for
> creating shared libraries from haskell I'd like to add it as an  
> explicit
> command line option to jhc.

So, what worked for me was just commenting out the main function and  
building with -fPIC and -shared from the gcc line from jhc -v.
It'd be nice to have a --no-hs-main like GHC has, and a separate C  
header file listing what's been exported would be cool, but otherwise  
it was all surprisingly smooth.

mark


More information about the jhc mailing list