On 9-Feb-08, at 4:18 AM, Neil Baylis wrote:
I'm building an executable that links with an object file that controls a machine via the USB bus.
I have this working OK by linking everything into an executable. But that means I must recompile every time I make a change to my scheme code. Instead, I'd like to be able to load the scheme code at runtime. Originally I wanted to compile my c code into a library so that I could load it with gsi. However i was unable to get that to work.
An example of this is given on page 11 of the Gambit manual. The X11 example (examples/X11-simple) also shows how you can do this.
Briefly, assume you have the Scheme file "s.scm" and the C file "c.c" and header file "c.h" which "s.scm" is interfacing with:
-------------------------------------------------------- ;; File: "s.scm" (c-declare "#include "c.h"") (define square (c-lambda (int) int "square")) -------------------------------------------------------- /* File: "c.h" */ int square (int x); -------------------------------------------------------- /* File: "c.c" */ int square (int x) { return x*x; } --------------------------------------------------------
Then you can simply do this:
% gsc -cc-options "c.c" s.scm
[Note that if you embed the code of c.c in the c-declare of s.scm, you can avoid the -cc-options "c.c"]
then
% gsi s -
(square 10)
100
or
% gsi Gambit v4.2.2
(load "s") (square 10)
100
If you need to include some special header files, or link with a special C library then something like this is needed:
% gsc -cc-options "-I/usr/include/foo c.c" -ld-options "-L/usr/lib/ foo -lfoo" s.scm
Marc