HypothesisC LanguageThe two written functions are:
Void hello_user (const char * Name) {printf ("Hello, % S. \ n", name); return;} void goodbye () {printf ("goodbye! \ N "); return ;}
If you want to call a function written by C in Chibi-scheme
Step 1: Create the stub File
You can create a test. Stub file with the following content:
(Define-CVoidHello-user (String))
(Define-CVoid(So-LongGoodbye )())
By default, the hello-user is converted to the hello_user in C language, and the short row is converted to an underscore. Or provide an alias. The Goodbye of C is named as so-long in scheme.
Step 2: Process stub files
Chibi-scheme provides a tool Chibi-FFI.
$ Chibi-scheme.../tools/genstubs. SCM Test. Stub
This will generate a test. c
Step 3: compile it into a dynamic link library
$ Gcc-FPIC-shared-I.../include/-l...-O hello. So hello. C test. C-lchibi-Scheme
Step 4: Load
Load the hello. So file in scheme to call the above function.
$ Chibi-Scheme
> (Load"./Hello. So")
> (Hello-user"Taylor")
Hello, Taylor.
> (So-Long)
Goodbye!