chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] static library and link


From: felix winkelmann
Subject: Re: [Chicken-users] static library and link
Date: Wed, 24 May 2006 08:40:25 +0200

On 5/24/06, John Cowan <address@hidden> wrote:
felix winkelmann scripsit:

> Not at all dumb - the documentation is a bit weak on that.

Can you lay out for us the principles behind what's built-in,
what's in a unit, and what ought to go in an egg?

Ok, say we have the following files:

; x.scm
(declare (unit x))
(define (do-x) (print "do-x in x called."))

; y.scm
(declare (unit y))
(define (do-y) (print "do-y in y called."))

; z.scm
(declare (uses x y))
(do-x)
(do-y)

The simplest model is static linking - we just compile the library units
into object files and link them with out application:

% csc -c x.scm
% csc -c y.scm
% csc z.scm x.o y.o -o z

We can also combine multiple library units into a static library:

% ar cru libxy.a x.o y.o
% csc z.scm -L. -lxy

Combining them into a shared library with explicit loading is also
possible:

; z2.scm
(load-library 'x "./libxy.so")
(load-library 'y "./libxy.so")
(do-x)
(do-y)

% csc -s x.scm y.scm -o xy.so
% csc z2.scm

Note that this is a bit of a non-standard use (hence the warnings while
compiling x.scm and y.scm). Still, this is the way builtin library-units
(srfi-1, tinyclos, etc.) are handled.

But the canonical way (and the way that integrates best into everything
and which reduces the distinction between compiled and interpreted
code) is to compile each file into a separate shared object:

; x2.scm
(define (do-x) (print "do-x in x called."))

; y2.scm
(define (do-y) (print "do-y in y called."))

; z3.scm
(use x2 y2)
(do-x)
(do-y)

% csc -s x2.scm
% csc -s y2.scm
% csc z.scm

"use"/"require" is just a funky form of "load" and automatically prefers
.so's to .scm's (but handles the latter if no .so can be found).

I recommend the last approach, unless you have really many different
libraries and want to package them in one binary - then the load-library
approach is appropriate.

I hope this helps a little.


cheers,
felix




reply via email to

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