<div dir="ltr"><div>Hi,</div><div><br></div><div>I have the following lisp file:</div><div><br></div><div>---</div><div>$ cat hello-lisp.lisp</div><div><br></div><div>(defun hello-lisp () (format t "hello-lisp!~%"))</div>
<div>---</div><div><br></div><div>and would like to call the function (hello-lisp) from the following c file:</div><div><br></div><div>---</div><div>$ cat hello.c</div><div><br></div><div>#include <stdio.h></div><div>
#include <ecl/ecl.h></div><div><br></div><div>int main (int argc, char **argv) {</div><div> cl_boot(argc, argv);</div><div><br></div><div> // evaluating (hello-lisp)</div><div> cl_eval(c_string_to_object("(hello-lisp)"));</div>
<div><br></div><div> cl_shutdown();</div><div> return 0;</div><div>}</div><div>---</div><div><br></div><div>On my Mac I compiled and linked the files as follows:</div><div><br></div><div>---</div><div>ecl -eval '(compile-file "hello-lisp.lisp" :system-p t)' -eval '(quit)'</div>
<div>gcc -Wall -c `ecl-config --cflags` -c hello.c</div><div>gcc -Wall -o hello `ecl-config --libs` hello-lisp.o hello.o</div><div>---</div><div><br></div><div>But when executing the file 'hello' I get the following error:</div>
<div><br></div><div>---</div><div>./hello </div><div><br></div><div>Condition of type: UNDEFINED-FUNCTION</div><div>The function HELLO-LISP is undefined.</div><div>No restarts available.</div><div><br></div><div>Top level in: #<process TOP-LEVEL>.</div>
<div>></div><div>---</div><div><br></div><div style>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.</div>
<div><br></div><div>How can I make this simple example work?</div><div><br></div><div><div>Thanks, </div><div><br></div><div>Dietrich</div></div><div><br></div><div>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. </div>
<div><br></div><div>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.</div>
<div><br></div><div style>So the ideal procedure would be something like this</div><div style><br></div><div style> - translate lisp files to c files</div><div style> - compile c files to object files</div><div style> - link the object files</div>
<div style><br></div><div style>as this would be easier to integrate with MS VC++.</div><div style><br></div><div style><br></div><div style><br></div></div>