Created
May 9, 2014 16:31
-
-
Save anonymous/6bd6236d741a48d03f5f to your computer and use it in GitHub Desktop.
CHICKEN library with C API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(foreign-declare "#include \"test.h\"") | |
(define-external (test_doit) void | |
(display "Hello world!") | |
(newline)) | |
(return-to-host) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chicken.h> | |
#include <stdio.h> | |
#include "test.h" | |
void test_init() { | |
puts(";; initializing chicken"); | |
if(!CHICKEN_run(C_toplevel)) { | |
puts(";; initialization failed"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include "test.h" | |
int main() { | |
puts(";; initializing library"); | |
test_init(); | |
puts(";; calling function"); | |
test_doit(); | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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