chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] foreign-lambda* ?


From: Thomas Chust
Subject: Re: [Chicken-users] foreign-lambda* ?
Date: Tue, 12 Jul 2005 11:35:54 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317)

Raffael Cavallaro wrote:
[...]
Can someone provide a simple 5 line example of how to correctly embed C code in Scheme using foreign-lambda* and/or friends? Just a simple function will do. I'm trying to figure out a persistent linker error when I use these, and I want to make sure It isn't my test code that is the problem.
[...]

Hello,

you could try something along these lines:

imurph:~ murphy$ csi -version
 ______ __     __        __
|      |  |--.|__|.----.|  |--.-----.-----.
|   ---|     ||  ||  __||    <|  -__|     |
|______|__|__||__||____||__|__|_____|__|__|
Version 1, Build 942 - macosx-unix-gnu-ppc - [ dload ]
(c)2000-2005 Felix L. Winkelmann
imurph:~ murphy$ cat >flt.scm
(define my-strlen
  (foreign-lambda* int ((c-string str))
                   "int n = 0;"
                   "while(*(str++)) ++n;"
                   "return(n);"))

(print (my-strlen "one two three")) ; prints 13
imurph:~ murphy$ csc -O2 -v -o flt flt.scm
/usr/local/bin/chicken flt.scm -output-file flt.c -quiet -optimize-level 2
gcc flt.c -o flt.o -DHAVE_CHICKEN_CONFIG_H -Os -fomit-frame-pointer -fno-strict-aliasing -Wall -Wno-unused -Wno-uninitialized -DHAVE_ALLOCA_H -no-cpp-precomp -DC_STACK_GROWS_DOWNWARD=1 "-DC_INSTALL_LIB_HOME=\"/usr/local/lib/chicken\"" "-DC_INSTALL_HOME=\"/usr/local/share/chicken\"" -DC_USE_C_DEFAULTS -c -DC_NO_PIC_NO_DLL
rm flt.c
gcc -o flt flt.o -lchicken -L/usr/local/lib -ldl -lm  -ldl
rm flt.o
imurph:~ murphy$ ./flt
13

By the way, I'm running Mac OS X 10.4.1 with gcc-4.0 as well, so it shouldn't be a system problem.

cu,
Thomas Chust




reply via email to

[Prev in Thread] Current Thread [Next in Thread]