I'm trying to write a simple program in Chicken Scheme with some inline C on OS X where Chicken has been installed with homebrew.
;; add1.ss
(import foreign)
(define add-1
(foreign-lambda* long ((unsigned-long x))
"
long n = 1
C_return(n + x);))
(print (add-1 (read)))
The foreign
library I am interested in definitely exists.
find /usr/local | grep chicken | grep foreign | grep lib
/usr/local//Cellar/chicken/5.0.0/lib/chicken/9/chicken.foreign.import.so
But, compiling my program via csc add1.ss
with no flags in the CSC_OPTIONS
environment variables produces:
$ csc add1.ss
Syntax error (import): cannot import from undefined module
foreign
Expansion history:
<syntax> (##core#begin (import foreign))
<syntax> (import foreign) <--
Error:shell command terminated with non-zero exit status 17920:
'/usr/local/Cellar/chicken/bin/5.0.0/bin/chicken' 'add1.ss' -output-file 'add1.c'
So, this error message makes a lot of sense, running
$ chicken add1.ss -output-file add1.c
produces the same failure. The only command line option seemingly related to path management in the chicken manpage is -include-path
. I tried the following incantations, and all of them produced the same error
$ chicken add1.ss -output-file add1.c -include-path /usr/local/Cellar/chicken/5.0.0/lib/chicken/9/chicken.foreign.import.so
$ chicken add1.ss -output-file add1.c -include-path /usr/local/Cellar/chicken/5.0.0/lib/chicken/9
$ chicken add1.ss -output-file add1.c -include-path /usr/local/Cellar/chicken/5.0.0/lib/chicken
$ chicken add1.ss -output-file add1.c -include-path /usr/local/Cellar/chicken/5.0.0/lib
$ chicken add1.ss -output-file add1.c -include-path /usr/local/Cellar/chicken/5.0.0
I also tried passing the chicken.foreign.import.so
as an additional "file to be compiled" but to no avail:
$ chicken add1.ss -output-file add1.c /usr/local/Cellar/chicken/5.0.0/lib/chicken/9/chicken.foreign.import.so
which produced the same error message.
What is the right way to direct chicken
or the compiler driver csc
to look for Chicken's internal libraries in the directory under /usr/local/Cellar/chicken/...
?
foreign
is the old name of that module, from CHICKEN 4. You've installed CHICKEN 5, where we have completely refactored all modules. This particular one has simply been renamed for consistency with the other ones. In CHICKEN 5, this module is called (chicken foreign)
So you would need to do
(import (chicken foreign))