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

Sean D'Epagnier sean at depagnier.com
Tue Feb 6 23:46:45 EST 2007


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



More information about the Gambit-list mailing list