Hi,

I have the following lisp file:

---
$ cat hello-lisp.lisp

(defun hello-lisp () (format t "hello-lisp!~%"))
---

and would like to call the function (hello-lisp) from the following c file:

---
$ cat hello.c

#include <stdio.h>
#include <ecl/ecl.h>

int main (int argc, char **argv) {
  cl_boot(argc, argv);

  // evaluating (hello-lisp)
  cl_eval(c_string_to_object("(hello-lisp)"));

  cl_shutdown();
  return 0;
}
---

On my Mac I compiled and linked the files as follows:

---
ecl -eval '(compile-file "hello-lisp.lisp" :system-p t)' -eval '(quit)'
gcc -Wall -c `ecl-config --cflags` -c hello.c
gcc -Wall -o hello `ecl-config --libs` hello-lisp.o hello.o
---

But when executing the file 'hello' I get the following error:

---
./hello

Condition of type: UNDEFINED-FUNCTION
The function HELLO-LISP is undefined.
No restarts available.

Top level in: #<process TOP-LEVEL>.
>
---

I tried to solve this problem by including the hello-lisp.eclh file which
is generated when using (compile-file "hello-lisp.lisp" :h-file t) but this
didn't solve the problem either.  I am not yet able to understand the
generated c code and therefore don't understand how to use it correctly.

How can I make this simple example work?

Thanks,

Dietrich

I am currently working on a Mac but ultimately have to make the example
work with MS VC++.  This is why I prefer to call the c compiler and linker
myself rather than using ECLs lisp based build tools like c::build-program,
etc.

For the same reason I would also prefer to separate the translation of lisp
files into c and object files.  But I couldn't find a way to compile a lisp
file to c without producing an object or fasl file in the same time as it
is done when using (compile-file ...).  I tried ':o-file nil' but even if
this parameter is mentioned in the help text of (compile-file ...) it seems
to not have been implemented yet.  I would be grateful about help
concerning this point as well.

So the ideal procedure would be something like this

  - translate lisp files to c files
  - compile c files to object files
  - link the object files

as this would be easier to integrate with MS VC++.
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list

Reply via email to