[Ecls-list] calling ECL functions defined in an ASDF package from C code

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun Jun 26 09:02:07 UTC 2011


On Sun, Jun 26, 2011 at 7:11 AM, Eric Schulte <schulte.eric at gmail.com>wrote:

> attempting to compile this program results in the following error message
>
>    $ gcc -o use -L. -lecl -lfoo
>    /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../crt1.o: In
> function `_start':
>    [.text+0x20]: undefined reference to `main'
>    collect2: ld returned 1 exit status
>

The order of libraries is wrong and this is missing a C file (use.c) that
calls the library.  This should have read

gcc -o use use.c -L. -lfoo -lecl

I have uploaded a fixed version of ECL that adds a warning about the files
that one tries to link into a standalone DLL. It follows a real session of
how this works right now

$ ecl -norc
ECL (Embeddable Common-Lisp) 11.1.1
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level.
> (require :cmp)

;;; Loading #P"/Users/jjgarcia/lib/ecl-11.1.1/cmp.fas"
("CMP")
> (c::build-shared-library "foo" :lisp-files (list (compile-file "foo"
:system-p t :verbose nil)))

;;; Compiling (DEFUN FOO ...).
;;; Emitting code for FOO.
;;; Note:
;;;   Invoking external command:
;;;   gcc -I. -I/Users/jjgarcia/include/ -g -O2 -fPIC -fno-common -Ddarwin
-O2 -w -c foo.c -o foo.o
"common-lisp-user::foo common-lisp-user::hola 0"
Condition of type: SIMPLE-ERROR
In C:BUILDER, when building file
 libfoo.dylib
tried to link together files that contained split binary data.
Unfortunately this is currently not possible. To avoid this
recompile the files setting C::*COMPILE-IN-CONSTANTS* to T.
List of offending files:
 #P"/Users/jjgarcia/foo.o"

Available restarts:

1. (RESTART-TOPLEVEL) Go back to Top-Level REPL.

Broken at SI:BYTECODES. [Evaluation of: (C:BUILD-SHARED-LIBRARY "foo"
:LISP-FILES (LIST (COMPILE-FILE "foo" :SYSTEM-P T :VERBOSE NIL)))]
>> :q

Top level.
> (setf c::*compile-in-constants* t)

T
> (c::build-shared-library "foo" :lisp-files (list (compile-file "foo"
:system-p t :verbose nil)))
;;; Compiling (DEFUN FOO ...).
;;; Emitting code for FOO.
;;; [...]
;;; Note:
;;;   Library initialization function is main_dll_FOO
;;; [...]
#P"libfoo.dylib"
> (si::system "gcc -o main.exe main.c -L$HOME/lib -L./ -lfoo -lecl")

0
> (si::system "./main.exe")

HOLA
0


-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20110626/6f306689/attachment.html>


More information about the ecl-devel mailing list