Re: [CM] s7 wrap c function with scheme
ex1.c is the repl from the start of the FFI example section. If you build s7 with WITH_MAIN, you don't need it. ___ Cmdist mailing list Cmdist@ccrma.stanford.edu https://cm-mail.stanford.edu/mailman/listinfo/cmdist
[CM] s7 wrap c function with scheme
Hi, The wrapper example below works great. Seems like -DWITH_MAIN, and -DUSE_SND=0 adds some special help. Thanks so much for that info. I'm moving on also to look at cload.scm now, but confused about the s7 manual example compile lines which shows an "ex1.c". I wasn't clear about what is ex1.c, or maybe my brain is just not reading the cload example correctly. gcc -c s7.c -I. gcc -o ex1 ex1.c s7.o -lm -I. -ldl -Wl,-export-dynamic ex1 > (load "cload.scm") ... Regards, Jim --- gcc -fpic -c add1.c gcc -shared -Wl,-soname,libadd1.so -o libadd1.so add1.o -lm -lc gcc s7.c -o repl -fpic -DWITH_MAIN -I. -ldl -lm -Wl,-export-dynamic -DUSE_SND=0 >./repl > (load "libadd1.so" (inlet 'init_func 'add1_init)) > (add1 2) #include #include "s7.h" static s7_pointer add1(s7_scheme *sc, s7_pointer args) { if (s7_is_integer(s7_car(args))) return(s7_make_integer(sc, 1 + s7_integer(s7_car(args; return(s7_wrong_type_arg_error(sc, "add1", 1, s7_car(args), "an integer")); } void add1_init(s7_scheme *sc); void add1_init(s7_scheme *sc) { s7_define_function(sc, "add1", add1, 1, 0, false, "(add1 int) adds 1 to int"); } ___ Cmdist mailing list Cmdist@ccrma.stanford.edu https://cm-mail.stanford.edu/mailman/listinfo/cmdist
Re: [CM] s7 wrap c func with scheme
Probably the simplest way to make a C function callable from s7 is to wrap it in a function of the form s7_pointer wrapper(s7_scheme *sc, s7_pointer args) Then get the scheme-side arguments from "args", and wrap the C function's output using the s7_make* functions. It is then defined in s7 using s7_define_function. s7.html has an example under "Define a function with arguments". If you want this in a shared library, you also need to tell s7's load function how to get the wrappers. This is normally done via an environment with a field named 'init_func whose value is the (name of the) C initialization function in the library (i.e. the function that calls s7_define_function). There's an example in the section about libsndlib.so, but maybe I should add a simpler example. cload.scm sets up all these wrappers and linkages for you, but it is overkill for simple cases. ___ Cmdist mailing list Cmdist@ccrma.stanford.edu https://cm-mail.stanford.edu/mailman/listinfo/cmdist
[CM] s7 wrap c func with scheme
Hi, I had a question about wrapping a c func with scheme, s7. I'm trying to understand how to wrap the declared function from the .h file with scheme in a .scm file (mywrapper.scm) so that it can be called from s7 and use the shared library. > (load mywrapper.scm) > (myfunction) > (exit) I have a .c file which includes a function (myfunction), and .h which declares that function. I compile the .c file using -fpic into an obj. file, then create a shared library, ex. mylib.so. I'm looking at SND files libc.scm and libgsl.scm which seem to be wrappers, but are quite complicated. I'm also looking at the S7 manual example for "Load a shared library", but there are static s7_pointer functions in the example's c code which seem to be doing the wrapping on the c side as opposed to wrapping a c function in scheme using a .scm file. I'm wondering if there's a simpler example somplace where I can get some ideas about how to go about wrapping a c function in scheme, or if the manual vers. is the preferred way to go, i.e. create a library using s7 functions from c, and then load the library into s7 to call the function? Regards, Jim ___ Cmdist mailing list Cmdist@ccrma.stanford.edu https://cm-mail.stanford.edu/mailman/listinfo/cmdist
[CM] s7 and c
re: gcc -o repel_test repel_test.c s7.o -Wl, -export-dynamic -lm -I. -ldl I think your problem is that you have a space after -Wl, -- it'a all one argument: -Wl,-export-dynamic --- Yes. Great. Thank you. I was stumped, but am now off and compiling. Regards, Jim ___ Cmdist mailing list Cmdist@ccrma.stanford.edu https://cm-mail.stanford.edu/mailman/listinfo/cmdist
[CM] s7 with c
Hi, I'm stuck on figuring out compiling a simple s7 repel test in c. I'm on fedora 23. I've tried a few different things but not sure what /usr/bin/ld error is trying to tell me. gcc error: /usr/bin/ld: cannot find : No such file or directory //gcc -o repel_test repel_test.c s7.o -Wl, -export-dynamic -lm -I. -ldl #include "/opt/snd-16/s7.h" int main (int argc, char **argv) { s7_scheme *sc; sc = s7_init(); s7_load(sc, "/opt/snd-16/repl.scm"); s7_eval_c_string(sc, "((*repl* 'run))"); return(0); } Regards, Jim ___ Cmdist mailing list Cmdist@ccrma.stanford.edu https://cm-mail.stanford.edu/mailman/listinfo/cmdist