calling scheme function from C added by rgherdt on Sun Mar 10 15:34:21 2024

;; my-lib.scm
;; compiled with:
;;   csc -c -e my-lib.scm

(import (chicken foreign))

(define (my-func x)
  (* x x))

(define-external (scm_my_func (int x)) int
  (my-func x))

;; main.c
;; compiled with:
;;   gcc main.c my-lib.o -I/usr/local/include/chicken -lchicken

#include <stdio.h>
#include <stdlib.h>
#include <chicken.h>

extern int scm_my_func(int x);

int main()
{
        CHICKEN_run(CHICKEN_default_toplevel);
        printf("result: %d\n", scm_my_func(5));
        exit(0);
}