ghc, FFI and autotools
We are trying to build and call some Haskell code in and from from the open-src spreadsheet "gn'meric". It seems that it could be a good basis for experiments in FP + SSs. We have worked through the simple FFI examples and can create small C+Haskell stand-alone programs. However, gnu'eric is quite a large program and autoconf|automake|...|libtools are used to build it. Consequently one does not have an entirely free hand to just compile and link the pieces in any old way. It has to fit in with the general build scheme. There is a general pattern to 'eric's "plugins": add a directory, e.g. ...../plugins/haskell/Makefile.am --->Mafilefile.in--->Makefile /functions.c -- the plugin's code /.... and we can make C-only plugins. The next step, or "impasse" to give it the technical name, is to add /functionsH.hs -- Haskell called from functions.c ? Please has anybody used ghc in this type of environment before, and ? have advice on the exercise in general or on ? creating a *shared library* from C + Haskell code in particular ? We[*] have tried a few things, so far with less than complete success, and often featuring undefined labels,-( e.g. E Unable to open module file "/home/lloyd/gnumeric/install//lib/gnumeric/1.2.1-bonobo/plugins/haskell/plugin.la". E /home/lloyd/gnumeric/install//lib/gnumeric/1.2.1-bonobo/plugins/haskell/plugin.so: undefined symbol: GHCziInt_I8zh_con_info Lloyd -- Lloyd ALLISON, CSSE, Monash University, Victoria, Australia 3800. web: http://www.csse.monash.edu.au/~lloyd/ tel: +61 3 9905 5205 use: http://www.linux.org/ OpenOffice: http://www.openoffice.org/ PS. [*] Not a royal we.
On Fri, Nov 21, 2003 at 10:49:43PM +1100, Lloyd Allison wrote:
We are trying to build and call some Haskell code in and from from the open-src spreadsheet "gn'meric". It seems that it could be a good basis for experiments in FP + SSs.
Hi, I'm afraid I don't have anything helpful to say, as even my last attempt to install gnumeric failed (due to lots of too-old libraries. I'm planning to retry some day) but it sounds great :) So I'd say, good luck and I'd be interested to hear more about it. Happy hacking, Remi -- Nobody can be exactly like me. Even I have trouble doing it.
Lloyd Allison <Lloyd.Allison@infotech.monash.edu.au> wrote,
The next step, or "impasse" to give it the technical name, is to add
/functionsH.hs -- Haskell called from functions.c
? Please has anybody used ghc in this type of environment before, and ? have advice on the exercise in general or on ? creating a *shared library* from C + Haskell code in particular ?
GHC cannot produce shared libraries. However, maybe you can work around this in your case, as you - if I understand you correctly - don't really want shared library code generated by the Haskell compiler, but you want shared-library C code that calls into Haskell. All the Haskell code can be statically linked, I assume. Unfortunately, I can't give you a concrete recipe on how to set this up, but it sounds as if it were possible. However, it seems to me as if one problem that you encountered was that you didn't link GHC's standard libraries to your code. More precisely, you will need to link GHC's runtime system and the standard libraries statically with your Haskell library. Around this you can try to craft a layer of C functions that can be dynamically linked. Cheers, Manuel
It sounds plausible to have shared-library C-code that is statically linked to Haskell code but it also sounds as if there could be subtle (beyond me), important distinctions here? Our local who knows most about autotools typically manages to remove (define) one of the undef' Haskell library labels and then another one replaces it. A typical (not working) effort is here... http://www.csse.monash.edu.au/~lloyd/tildeProgLang/Gnumeric/latest/haskell/ the problem area is what should be done in Makefile.am around about ... $(LIBTOOL) --mode=compile $(HSCOMPILE) $(INCLUDES) -c $< -o $@ $(HSCOMPILE) -DPIC $(INCLUDES) -c $< -o $@ ... A gnu'eric plugin gets dynamically loaded, as I understand it, when a particular one is required. Lloyd -- Lloyd ALLISON, CSSE, Monash University, Victoria, Australia 3800. web: http://www.csse.monash.edu.au/~lloyd/ tel: +61 3 9905 5205 use: http://www.linux.org/ OpenOffice: http://www.openoffice.org/ On Sun, Nov 23, 2003 at 09:54:58PM +1100, Manuel M T Chakravarty wrote:
Lloyd Allison <Lloyd.Allison@infotech.monash.edu.au> wrote,
The next step, or "impasse" to give it the technical name, is to add
/functionsH.hs -- Haskell called from functions.c
? Please has anybody used ghc in this type of environment before, and ? have advice on the exercise in general or on ? creating a *shared library* from C + Haskell code in particular ?
GHC cannot produce shared libraries. However, maybe you can work around this in your case, as you - if I understand you correctly - don't really want shared library code generated by the Haskell compiler, but you want shared-library C code that calls into Haskell. All the Haskell code can be statically linked, I assume.
Unfortunately, I can't give you a concrete recipe on how to set this up, but it sounds as if it were possible. However, it seems to me as if one problem that you encountered was that you didn't link GHC's standard libraries to your code. More precisely, you will need to link GHC's runtime system and the standard libraries statically with your Haskell library. Around this you can try to craft a layer of C functions that can be dynamically linked. Cheers, Manuel
--
participants (3)
-
Lloyd Allison -
Manuel M T Chakravarty -
Remi Turk