I'm trying to use gsc to build a shared library, but I'm having issues. I've been through the info file and tried a host of build techniques, and while the library compiles fine when I try to use it my test executable segfaults somewhere in __garbage_collect(). I've pared it to a trivial situation:
library.scm:
(define (hello) (display "hello") (newline))
(c-define (c-hello) () void "hello" "" (hello))
Makefile:
gsc -link library gsc -obj -cc-options "-D___SHARED" library.c library_.c gcc -shared -o liblibrary.so library.o library_.o \ -L/home/evanhanson/.builds/gambc/lib -lgambc
test.c:
int main(int argc, char* argv[]) { hello(); return 0; }
And the backtrace from gdb:
#0 0x00007ffff782ea09 in ___garbage_collect () from ./libgambc.so #1 0x00007ffff782fbcc in ___alloc_scmobj () from ./libgambc.so #2 0x00007ffff782fd3b in ___make_vector () from ./libgambc.so #3 0x00007ffff78325ca in ___make_sfun_stack_marker () from ./libgambc.so #4 0x00007ffff741ce94 in hello () from ./libom.so #5 0x000000000040064d in main ()
I'm sure there's something simple I'm missing. Any suggestions?
Evan
Afficher les réponses par date
Hallo,
On Sun, Sep 19, 2010 at 11:24 PM, Evan Hanson vnhnsn@gmail.com wrote:
I'm trying to use gsc to build a shared library, but I'm having issues.
I'm sure there's something simple I'm missing. Any suggestions?
You must call ___setup() to initialise the Gambit-C runtime.
Yes, I have produced working executables that way. I was hoping there might be a way to produce a library that exports the defined functions without requiring the setup calls. I take it this isn't possible, or I'm using the wrong approach to achieve what I want...
Evan
On Sun, Sep 19, 2010 at 9:26 PM, Alex Queiroz asandroq@gmail.com wrote:
Hallo,
On Sun, Sep 19, 2010 at 11:24 PM, Evan Hanson vnhnsn@gmail.com wrote:
I'm trying to use gsc to build a shared library, but I'm having issues.
I'm sure there's something simple I'm missing. Any suggestions?
You must call ___setup() to initialise the Gambit-C runtime.
-- -alex http://www.artisancoder.com/
Hallo,
On Sun, Sep 19, 2010 at 11:38 PM, Evan Hanson vnhnsn@gmail.com wrote:
Yes, I have produced working executables that way. I was hoping there might be a way to produce a library that exports the defined functions without requiring the setup calls. I take it this isn't possible, or I'm using the wrong approach to achieve what I want...
You may use GCC's "constructor" and "destructor" function attributes:
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
In Windows the setup would be done in DllMain().
Interesting, thanks for the link. I just wrapped the setup calls from within the library, but that looks like a nicer solution.
Thanks,
Evan
On Sun, Sep 19, 2010 at 9:44 PM, Alex Queiroz asandroq@gmail.com wrote:
Hallo,
On Sun, Sep 19, 2010 at 11:38 PM, Evan Hanson vnhnsn@gmail.com wrote:
Yes, I have produced working executables that way. I was hoping there
might
be a way to produce a library that exports the defined functions without requiring the setup calls. I take it this isn't possible, or I'm using
the
wrong approach to achieve what I want...
You may use GCC's "constructor" and "destructor" function attributes:
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
In Windows the setup would be done in DllMain().
-- -alex http://www.artisancoder.com/