[gambit-list] calling scheme with a dlopen in c

Guillaume Germain guillaume.germain at gmail.com
Wed Feb 7 22:31:01 EST 2007


Hi Sean,

I'm not sure whether this will solve your exact problem, but here's a full
example of generating a shared library (.so) where functions are implemented
in Scheme and called from C:

http://toute.ca/tmp/gambit_dynamic_library.tar.gz

Just run "make test" to see it work.

Hope this helps,


Guillaume



On 2/6/07, Sean D'Epagnier <sean at depagnier.com> wrote:
>
> Sorry I forgot to insert my message:
>
> I have a program written in c that dlopens shared libraries
> that contain math functions.  I would like to have the option
> to write these functions in scheme without adding too much
> plumbing to the c code.  I would just give it the .so name
>
> I tried to use the c-define special form as it can wrap regular
> scheme procedures.  I compiled the output from gsc to a .so
> file using gcc, and dlopened it with a simple c program, I got
> the function pointer, but when I called it I get:
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00002aaaab31acf5 in ___garbage_collect () from ./libtest.so
>
> I saw the server.scm and client.c example in the /tests directory.
> Would it make sense to put this setup code in the shared library's
> init routine?  What if I load multiple libraries this way?
>
> For a test I put this setup code in the sample c program, but it
> requires the "#define SCHEME_LIBRARY_LINKER" macro to be set to a name,
> this is a bit of a problem since I don't know the name and I want
> to load an arbitrary number of libraries.
>
> I did for a test put in the name of the sample library, and it did
> work when I called the function pointer I got from dlsym.
>
> Any hints on how to get around the SCHEME_LIBRARY_LINKER restriction?
>
> Thanks
> Sean
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20070207/ebc6d945/attachment.htm>


More information about the Gambit-list mailing list