[Ecls-list] I do not understand how to link C modules with Lisp main prog

Juan Jose Garcia Ripoll worm at arrakis.es
Tue Apr 1 02:18:20 UTC 2003


On Monday 24 March 2003 18:05, Moshe Goldstein wrote:
> In summary:
> I wrote several Lisp functions that invoke C functions that I took from
> an open-source package. I compiled all the C program pieces using the -c
> -ansi options of gcc.
> I need to link all the pieces together to build a running program.
> The only thing I need in order to understand how to do it with ECL, is a
> complete tiny example, or a clear explanation of how to do it.

A scheme of how your linking stuff would look like:

(defvar *my-c-program-prologue* "
	/* All stuff which initializes your C libraries and registers your C
	   functions with ECL */
")

(defvar *my-c-program-epilogue* "
	/* When you do not want the lisp toplevel to handle the execution
	   write your own code here. Otherwise, set *my-c-program-epilogue* to
	  NIL. */
")

(if *my-c-program-epilogue*
  (c:build-program "myecl"
	:lisp-files '("hello.o")
	:ld-flags '("first-object-file.o" "second-object-file.o" "-Lf2c" ...)
	:prologue-code *my-c-program-prologue*
	:epilogue-code *my-c-program-epilogue*)
  (c:build-program "myecl"
	:lisp-files '("hello.o")
	:ld-flags '("first-object-file.o" "second-object-file.o" "-Lf2c" ...)
	:prologue-code *my-c-program-prologue*))

1) The PROLOGUE code is intended to perform initialization of your 
C/C++/FORTRAN/... stuff.

2) The EPILOGUE code should only be present when you want to replace the lisp 
toplevel (the interactive read-eval-execute loop) with your own routines.

3) :LD-FLAGS lists all flags to be passed to the linker. It includes your 
C/C++/FORTRAN/etc, object files, your favourite libraries, special flags, 
etc.

I am sorry I cannot supply a better example, but lacking a lot of free time, I 
decided to give priority to making ECL more stable and less buggy and not so 
much to write examples. This is where other people could easily contribute 
;-)

Juanjo





More information about the ecl-devel mailing list