[Ecls-list] How to compile and link lisp and c files?

Dietrich Bollmann dietrich at formgames.org
Fri May 31 03:18:48 UTC 2013


[Connecting this thread to the one providing the answer]

On Wed, May 29, 2013 at 2:42 AM, Dietrich Bollmann <dietrich at formgames.org>
 wrote:

> How can I make this simple example work?
>


> the ideal procedure would be something like this
>
>   - translate lisp files to c files
>   - compile c files to object files
>   - link the object files
>

See this thread for the solution:

  - [Ecls-list] Example about building / loading ECL libraries

http://sourceforge.net/mailarchive/forum.php?thread_name=CAMCvb%3DCyzbkyVJqNumSeozg8-Vn4ErO2ytS%3D7ui175HcQeYbsw%40mail.gmail.com&forum_name=ecls-list

Dietrich


On Wed, May 29, 2013 at 2:42 AM, Dietrich Bollmann
<dietrich at formgames.org>wrote:

> 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++.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20130531/a1d2e072/attachment.html>


More information about the ecl-devel mailing list