This is the mail archive of the guile@cygnus.com mailing list for the guile project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
On Fri, Apr 24, 1998 at 03:04:37PM +0200, Miroslav Silovic wrote:
> > I know I'll sound pretty dumb here, but I couldn't
> > actually get access to ANY of the matrix functions from mguile.
OK, the (use-modules (matrix)) call worked a treat.
So I had a good play with mguile and looked at how it fitted
together. I must say that the way g-wrap and libtool work is
still quite beyond me but at least I got something working.
I had a try at writing a few extensions of my own with some
success.
(I'll write that up in the next letter)
> Err, not quite. Modules are .scm files - they're just a way to
> restrict namespaces in Scheme.
Right, I dig this now. Dunno how to write one but I do know
where they live and what they do.
> You can load/initialize .so files with
> (dynamic-call 'function (dynamic-link "foo.so")).
Yup, got this working too.
At the moment I'm using the technique as follows:
-- in the C code (index.c) --
void initialise_for_scheme( void )
{
if( t16_index ) return;
t16_index = scm_newsmob( &index_smob ); /* can this return zero? */
gh_new_procedure( s_index_create, index_create, 1, 1, 0);
gh_new_procedure( s_index_insert, index_insert, 2, 0, 0);
gh_new_procedure( s_index_length, index_length, 1, 0, 0);
gh_new_procedure( s_index_search, index_search, 2, 0, 0);
gh_new_procedure( s_index_list, index_list, 1, 2, 0);
gh_new_procedure( s_index_remove, index_remove, 2, 0, 0);
}
-- in the Makefile --
index.so : index.c
gcc -shared -O2 $< -o $@
strip $@
-- then from the bash prompt --
$ make index.so
$ guile
guile> (dynamic-call 'initialise_for_scheme (dynamic-link "./index.so"))
guile> (INDEX -)
#<INDEX 80565a0>
guile>
--------------------------
And then I have access to my data type and primitives. Note that
this uses the normal guile which was compiled with no knowledge of
my extensions nor with any -lblahblah options other than the usual.
It doesn't use libtool or anything wierd.
If you want to do tidy it up a bit more, you would have to
install index.so into /usr/local/lib/guile_index.so.1.0,
softlink /usr/local/lib/guile_index.so.1 and write some suitable
scheme code to go into /usr/local/share/guile/site/inxex.scm
one line of which would be:
(dynamic-call 'initialise_for_scheme (dynamic-link "guile_index.so.1"))
And then anyone wanting to use the module would say:
(use-modules (index))
> .lo and .la files are used by libtool. Hmm, generally when I need
> shared lib, I just write automakefile (that's Makefile.am) and handle
> compilation from there. Now, you need .so files to link with Guile, so
> you call dynamic-link with install path and make sure that the .so is
> always installed before running Guile.
>
> This works, but makes compile cycle longer (by copying the files).
Well how does my method sound?
If it's simple enough that I can understand it then it's gotta
have some advantages.
Things to note are:
[1] The .so library does NOT link with -lguile and doesn't even need
guile to be installed for it to compile (well it needs the headers).
[2] The guile interpreter does not need to be recompiled at all.
[3]