Afficher les réponses par date
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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 6-Feb-07, at 11:46 PM, Sean D'Epagnier 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?
My suggestion is this: create a shared library that contains the Gambit runtime library and link each of your math function shared libraries with the Gambit runtime library. So when you load any of the math function libraries, the Gambit runtime library will automatically be loaded (and initialized).
If this is too abstract, let me know and I'll see if I can write some real code for this. What operating system are you using? How do you do your dlopen calls in C?
Marc
My suggestion is this: create a shared library that contains the Gambit runtime library and link each of your math function shared libraries with the Gambit runtime library. So when you load any of the math function libraries, the Gambit runtime library will automatically be loaded (and initialized).
I tried doing this, I have an empty scheme file that I use to make a library linked with the gambit runtime library, I use this library for the SCHEME_LIBRARY_LINKER define. Then I compiled a simple function to a .so file, dlopen it, I get an address for the function pointer with dlsym, but when I call the function I still get a segmentation fault.
If this is too abstract, let me know and I'll see if I can write some real code for this. What operating system are you using? How do you do your dlopen calls in C?
Marc
This is what I have so far: http://people.freedesktop.org/~geckosenator/dlopenscheme.tar.gz
I'm not quite sure where I went wrong.
Thanks, Sean
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@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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list