axiom-developer
[Top][All Lists]

## [Axiom-developer] Call Foreign C from Aldor/Axiom (fwd)

 From: hueber\"P Subject: [Axiom-developer] Call Foreign C from Aldor/Axiom (fwd) Date: Wed, 07 Jun 2006 14:42:19 +0200



Hi Camm and the Axiom developers,
I want to summarize my attempts to load external C libraries/functions
from within Aldor/Axiom. I hope a lisp/gcl guru can give me some advice

- especially on 2.3 ;-)
1) Functions need to be defined with "defentry" in an external file,
which has to be compiled an loaded. To ")lisp" the defentry does not
work?!
Now, external are known to underlying gcl and the functions can be

called.
2) Importing external objects or libraries is the actual problem (I hope

only for me):
2.1: "load" of the object generated from a C src does not work.
2.2: FFI, CFFI, "faslink" is not implemented on Linux, FreeBSD, ... or
GCL at all.
libraries  e.g. with libdl providing dlopen to import external shared
libs. This approach is used with elf-loader

(http://www.copyleft.de/lisp)
I tried to generate an interpsys image with compiler::link instead of
save-system. Yet unlucky, as you can read from the following error
message. I wonder why the compiler::link does not find the gcl libraries

while save-system works?
####################### build of interpsys ###################
[...]
Finished

/usr/bin/ld: cannot find -lgclp

Error: Cannot delete the file #p"./raw_axiomelf".
Error signalled by LET*.
Broken at APPLY.  Type :H for Help.

gmake[3]: ***

[/usr/ports/math/axiom/work/axiom--main--1--patch-47/obj/freebsd/bin/interps ys] Error 255
gmake[3]: Leaving directory
/usr/ports/math/axiom/work/axiom--main--1--patch-47/src/interp'
gmake[2]: *** [interpdir] Error 2
gmake[2]: Leaving directory
/usr/ports/math/axiom/work/axiom--main--1--patch-47/src'
gmake[1]: *** [srcdir] Error 2
gmake[1]: Leaving directory
/usr/ports/math/axiom/work/axiom--main--1--patch-47'
gmake: *** [all] Error 2
[...]

###################
There are some things I don't understand. I am using FreeBSD which
includes dlopen in libc. In gcl, printf is available, dlopen not???
See example below (syslisp.lsp includes a defentries for dlopen, nputs,
and printf).
Only printf works, IMHO dlopen should, nputs not (because it is a local

object)???
################### running plain gcl ###############

(compile-file "/usr/ghue.rw/axiom/syslisp.lsp")


Compiling /usr/ghue.rw/axiom/syslisp.lsp.
End of Pass 1.
End of Pass 2.
OPTIMIZE levels: Safety=0 (No runtime error checking), Space=0, Speed=3
Finished compiling /usr/ghue.rw/axiom/syslisp.lsp.

#p"/usr/ghue.rw/axiom/syslisp.o"
(load "/usr/ghue.rw/axiom/syslisp.o")


symbol "dlopen" is not in base imagesymbol "nputs" is not in base

376


#####################
3) Last open, but important issue has been pointed out by Peter
Types representation between Aldor/Axiom <-> Lisp <-> C,... has to be

considered. Thanks Gernot


On Fri, 2006-06-02 at 10:49 -0400, Bill Page wrote:

On June 2, 2006 5:54 AM Gernot Hueber wrote:
> ... Where/how did you place the defentry line. It didn't
> work out for me with )lisp ?!

> On this page http://wiki.axiom-developer.org/SandBoxAldorForeign the (defentry ... ) line is between
 \begin{lisp}
...

\end{lisp}
which means that it gets compiled into the current Axiom/Lisp image.

> > > > That's my confusion. I think what you need is (compiler::link ...)
> > but that is beyond my level of competitence with GCL. Lisp

> > > > Well, I never tried to use Lisp before using Axiom. What I found > googleing for compiler::link where examples generating a new > lisp image including addtional libs. Maybe it is possible to call > functions from this one??
Yes. As Tim Daly said, the best person and place to ask about this

Camm does also read this list so I hope he has time to reply. > My second idea was to use the dynamic loader (Linux: dlopen > from libdl; FreeBSD includes dlopen in libc), to load a missing
> library (converted to from my custom object). Actually Lisp told
> me, "dlopen" is not in the base image :-( At least I expected it
> to be, because it is in libc.

> > faslink and FFI are not implemented in GCL (and/or Linux/BSD/...) >
I think that is the right idea. As I understand it gcl can be
compiled with dlopen as an option but I don't know anything more

> > > > Although I still cannot call this routine as an external
> > library routine, I was able to compile and call it from
> > inside Axiom. See my extended example at:

> > > > http://wiki.axiom-developer.org/SandBoxAldorForeign
> >

> Great. > > My idea of doing all that is to be able to integrate external > libraries into Axiom/Aldor. And there are plenty interesting
> candidates (e.g. LAPACK, SDPA, ...)

> +1 Here, here!
Regards,

Bill Page.




`