chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] (load ...)


From: Graham Fawcett
Subject: Re: [Chicken-hackers] (load ...)
Date: Thu, 7 Jun 2007 16:01:13 -0400

On 6/7/07, Peter Keller <address@hidden> wrote:
On Thu, Jun 07, 2007 at 04:54:34PM +0000, Alejandro Forero Cuervo wrote:
> > So, in the case of compiling two files, one having (declare (uses x))
> > and the other (declare (unit x)) and compiling with two separate
> > commands (as in the manual), how does Chicken share the knoweldge about
> > what functions to call in unit x?

My advice, ignore the (declare (unit ..)) stuff unless you're trying to make a static executable, or something else really fancy. For regular work, use (require-extension) instead, or (use) which is an abbreviation for (require-extension).

Example:

;;; a.scm
(define (hello) (print "hello from A!"))

;;; b.scm
(use a)
(hello)

Now, run "csi -b b.scm" and you'll see:
; ...
; loading b.scm ...
; loading ./a.scm ...
hello from A!

Note (use) or (require-extension) didn't find a shared library named "a", so it loaded the "a.scm" source file instead.

now do this:
csc -s a.scm
csi -b b.scm

In other words, compile A into a shared library, and run B again:
; ...
; loading b.scm ...
; loading ./a.so
hello from A!

See the "a.so" line? It finds the A library before it looks for the A source file.

Note that if an extension named "a.so" had existed in my (chicken-repository), it would have been loaded instead, before csi looked in the current directory for a match. If you're running on Linux, you can demonstrate this using `strace`, watching the `stat` calls while csi is looking for something called " a.scm" or "a.so"...

strace -e trace=stat64  csi -b b.scm
...
stat64("b.scm", {st_mode=S_IFREG|0644, st_size=29, ...}) = 0
stat64("b.scm.so", 0xbfbd39b0)          = -1 ENOENT (No such file or directory)
stat64("b.scm.scm", 0xbfbd35a0)         = -1 ENOENT (No such file or directory)
; loading b.scm ...
stat64("/usr/local/lib/chicken/1/a.setup-info", 0xbfbdda10) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/chicken/1/a.so", 0xbfbd7680) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/chicken/1/a.scm", 0xbfbd70d0) = -1 ENOENT (No such file or directory)
stat64("/usr/local/share/chicken/a.so", 0xbfbd6520) = -1 ENOENT (No such file or directory)
stat64("/usr/local/share/chicken/a.scm", 0xbfbd5f70) = -1 ENOENT (No such file or directory)
stat64("./a.so", {st_mode=S_IFREG|0755, st_size=9570, ...}) = 0
stat64("./a", 0xbfbd4e10)               = -1 ENOENT (No such file or directory)
stat64("./a.so", {st_mode=S_IFREG|0755, st_size=9570, ...}) = 0
; loading ./a.so ...
hello from A!

Does this help?

Graham


reply via email to

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