[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] FFI and shared libraries

From: felix winkelmann
Subject: Re: [Chicken-users] FFI and shared libraries
Date: Mon, 3 Jan 2005 08:24:12 +0100

On Mon, 3 Jan 2005 01:28:51 +0000, Joel Reymont <address@hidden> wrote:
> Howdy!
> I have a number of Scheme units that I'm compiling into one shared
> library. I also have a couple of files that wrap existing C++ header
> files, one Scheme file per header file. I'm able to compile all these
> files into a shared library. I also compile into the shared library one
> "main" file where  I do (load-library 'unit "") for each Scheme
> unit. Then I do (declare (uses unit)) for each unit as well.
> Problem is that when I do the declare uses for those Scheme units that
> have FFI code it tries to load the Scheme file. If I don't put in
> (declare unit ... ) into the FFI Scheme files then I get multiple
> definitions of C_toplevel.
> I understand that I can create extension modules (shared libraries?) for
> each C++ header file or maybe one module with all the header files
> included. Is there a more elegant way, though?

Hm, I'm not exactly sure what you are doing here. If you use
'(declare (uses ...))' for each compiled file, then the load-library
should not be necessary. Couldn't you simply do this:
compile every Scheme module into a unit (with a proper unit declaration, or
the -unit compiler option), add -fPIC to the C compiler options (but
don't compile them as -shared), and then link them together:

% cat x.scm
(declare (unit foo))
(print "foo")
% cat y.scm
(declare (unit bar))
(print "bar")
% cat z.scm
(declare (uses foo bar))
(print "main")
% cat c.c
#include "chicken.h"

int main()
  CHICKEN_run(NULL, NULL, NULL, C_toplevel);
  return 0;
% csc x.scm -vc -C -fPIC
/usr/local/bin/chicken x.scm -output-file x.c -quiet
gcc x.c -o x.o -g -c -DC_NO_PIC_NO_DLL -fPIC
rm x.c
% csc y.scm -vc -C -fPIC
/usr/local/bin/chicken y.scm -output-file y.c -quiet
gcc y.c -o y.o -g -c -DC_NO_PIC_NO_DLL -fPIC
rm y.c
% csc z.scm -vc -C -fPIC
/usr/local/bin/chicken z.scm -output-file z.c -quiet
gcc z.c -o z.o -g -c -DC_NO_PIC_NO_DLL -fPIC
rm z.c
% gcc x.o y.o z.o -shared -o `chicken-config --libs` 
% LD_LIBRARY_PATH=. ./a.out

(this might not be exactly what you need, and I'm possible
completely misunderstanding the problem)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]