Use the FFI of Chibi-scheme to call C

Source: Internet
Author: User

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!
 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.