[Ecls-list] Fwd: Re: Re: Re: About Embed ECL into C programs

Juan Jose Garcia-Ripoll jjgarcia at users.sourceforge.net
Mon Nov 20 09:29:20 UTC 2006

2006/11/20, Huang Jianshi <hadeshuang at gmail.com>:
> Ok, let me state my problem clear. I have a poker game client written
> in C and I want to add some logic to the client. I wrote the logic
> part in Lisp and left the communication part in C.

So far so good. People have used ECL like that. XChat is an example.

> I need to submit it in the form of source code so the people there
> could make a standalone program on their machine (I'm in a programming
> contest actually).

Hmm, here there is something I do not understand. You will be
submitting the source of your lisp program after being translated to
C. But you will need ECL as well and you will have to submit it to the
contest. Then, why not let ECL compile your lisp logic? You can submit
it as well and integrate it as part of the build process for your
poker client.

1) Compile your lisp files as

(compile-file "myfile" :system-p t)

2) Build your application as a library (I will call it
pokerclient.lib) with an entry point different from "main". Let's say
start_client(int narg, char **argv)

3) Let ECL build your program using C:BUILD-PROGRAM:

(C:BUILD-PROGRAM "poker" :lisp-files ("myfile.o") :ld-flags

But since I assume your answer will be no, I will try to shed some
light on what you are doing. The problem with compiling the translated
file is that there are lots of things going on behind curtains. Those
are details even I do not even remember 100% First of all, the
translation produces 3 C files with extensions *.h, *.c, and *.data.
You will need the three of them:

(compile-file "myfile" :system-p t :c-file t :h-file :data-file t)

These files have to be registered with the lisp core. The code for
that is automatically generated by ECL depending on what you do with
it. I can only advise you but to inspect the routine
C:BUILD-STATIC-LIBRARY and C:BUILDER which are in src/cmp/cmpmain.lsp
You can remove the delete-file statements there to see what files it
generates and you can inspect the commands they invoke to see what
flags the C compiler is passed.

With the translated C files, the lisp core and the initialization code
for your lisp routines, you can then link things against your poker
client. Basically you will have to invoke first cl_boot(), then
register additional C functions with the lisp core, and finally invoke
the routine that initializes your lisp code (the name is something
like init_* and it is the one created by C:BUILD)

> I use ECL to generate the player.c from lisp code.
> Actually, it has two entries: change-cards-entry and play-cards-entry,
> and after the lisp-to-C compilation, their name became
> L1change_cards_entry and L2play_cards_entry, in player.c

Lisp functions are not expected to be called directly unless you know
what you are doing and tell the lisp compiler that it should export
those functions. They way to do it is

(proclaim '(ext:c-export-fname my-package:my-lisp-function-name))

This produces a C name for the function which is of the form


Alternatively use

(si:put-sysprop 'my-lisp-function-name 'Lfun "my_desired_C_name")

Hopes this helps,


More information about the ecl-devel mailing list