Skip to content

Instantly share code, notes, and snippets.

Created May 9, 2014 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6bd6236d741a48d03f5f to your computer and use it in GitHub Desktop.
Save anonymous/6bd6236d741a48d03f5f to your computer and use it in GitHub Desktop.
CHICKEN library with C API
(foreign-declare "#include \"test.h\"")
(define-external (test_doit) void
(display "Hello world!")
(newline))
(return-to-host)
#include <chicken.h>
#include <stdio.h>
#include "test.h"
void test_init() {
puts(";; initializing chicken");
if(!CHICKEN_run(C_toplevel)) {
puts(";; initialization failed");
}
}
#include <stdlib.h>
#include <stdio.h>
#include "test.h"
int main() {
puts(";; initializing library");
test_init();
puts(";; calling function");
test_doit();
return EXIT_SUCCESS;
}
CSC := csc
CSCFLAGS := -O2 -d1 -static-libs
CC := $(shell $(CSC) -cc-name)
CCFLAGS := -O2 -Wall
.PHONY: all
all: libtest.a test
.PHONY: clean
clean:
$(RM) libtest.a
$(RM) test
$(RM) *.o
libtest.a: init.o api.o
$(AR) cru $@ $^
test: main.o libtest.a
$(CSC) $(CSCFLAGS) $^ -o $@
init.o: init.c test.h
api.o: api.scm test.h
test.o: main.c test.h
$(CC) $(CCFLAGS) -c $< -o $@
%.o: %.c
$(CSC) $(CSCFLAGS) -c $< -o $@
%.o: %.scm
$(CSC) $(CSCFLAGS) -e -c $< -o $@
#ifndef _test_h_
#define _test_h_
#ifdef __cplusplus
extern "C" {
#endif
void test_init(void);
void test_doit(void);
#ifdef __cplusplus
}
#endif
#endif /* _test_h_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment