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

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Mon May 3 13:53:29 UTC 2010


On Mon, May 3, 2010 at 3:44 PM, Seth Burleigh <seth at tewebs.com> wrote:

> > 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.
> 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)
> "/tmp/ECL0055CnScz.o"
> /tmp/ECL0055CnScz.c: In function ‘cl_lispunion* L1test()’:
> /tmp/ECL0055CnScz.c:16: error: ‘foo’ was not declared in this scope


This is a limitation of the compiler and linker. The function "foo" is
defined and loaded in memory, but we have not told the compiler about this
function and second in some platforms it will be impossible to let the
compile code use the "foo" function which is only in memory and not in a
library. So the message is that this is not portable at all, but in some
platforms it is possible. For instance, this is Mac OS X

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

TEST
> (compile 'test)
[...]
Undefined symbols:
  "_foo", referenced from:
      _L1test in ECL001YyIGUB.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
> (setf c:*user-ld-flags* '("-Wl,-undefined,dynamic_lookup"))

("-Wl,-undefined,dynamic_lookup")
> (compile 'test)
[...]
> (test)

3
3



-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://tream.dreamhosters.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100503/0f0a1cf4/attachment.html>


More information about the ecl-devel mailing list