[Ecls-list] Tighter c/c++ integration, toplevel inline c/c++ code ???

Seth Burleigh seth at tewebs.com
Mon May 3 13:44:00 UTC 2010


> 
>         But besides that, i tested your code and was wondering how i
>         access the
>         c code from the REPL.
> 
> 
> This is not possible because we are no C/C++ interpreter. You need to
> compile and load the compiled files first.
> 

I did compile it. I compiled foo.lisp and loaded it. Then i defined the
function test on the repl which used the c function defined in foo.lisp
and then compiled that. It said that the function wasn't declared in the
current scope. I do not know how i would export the c functions which
are defined so i can use them in compiled code that i produce on the
repl, or in other lisp files.

foo.lisp:
(FFI:CLINES "
int foo(int a, int b)
{
return a+b;
}
")

REPL (after loading foo.fas):


UTILS2> (defun test () 
  (let ((x (ffi:c-inline (1 2) (:int :int) :int "foo(#0,#1)" :one-liner
t)))
    (print x)))

TEST
UTILS2> (compile 'test)

;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
;;; Note:
;;;   Invoking external command:
;;;   g++ "-I/usr/local/include/"  -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
-g -O2 -fPIC  -Dlinux -O -w -c "/tmp/ECL0055CnScz.c" -o
"/tmp/ECL0055CnScz.o"
/tmp/ECL0055CnScz.c: In function ‘cl_lispunion* L1test()’:
/tmp/ECL0055CnScz.c:16: error: ‘foo’ was not declared in this scope
;;; 
;;; Internal error:
;;;   ** (SYSTEM "g++ \"-I/usr/local/include/\"  -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -g -O2 -fPIC  -Dlinux -O -w -c
\"/tmp/ECL0055CnScz.c\" -o \"/tmp/ECL0055CnScz.o\"") returned non-zero
value 1
TEST
NIL
NIL






More information about the ecl-devel mailing list