Hi all,

Is there am easy way of generating a shared library with all the
scheme definitions generated in code by the C++ macro LY_DEFINE and
friends? I would like have a way of testing scheme files from the
Guile repl.

It would take some of the grief out of hacking for the Guile V2 scheme
port as I can debug and test scheme files from the shell and the REPL
without having to hack lily.scm all the time.

Cheers,

Ian Hulin

(This is from the Guile documentation, what I'm after is the
equivalent of the libguile-bessel.so )

=======================================================================
A library that is linked into Guile is called an extension, but it
really just is an ordinary object library.

The following example shows how to write a simple extension for Guile
that makes the j0 function available to Scheme code.

     #include <math.h>
     #include <libguile.h>

     SCM
     j0_wrapper (SCM x)
     {
       return scm_make_real (j0 (scm_num2dbl (x, "j0")));
     }

     void
     init_bessel ()
     {
       scm_c_define_gsubr ("j0", 1, 0, 0, j0_wrapper);
     }

This C source file needs to be compiled into a shared library. Here is
how to do it on GNU/Linux:

     gcc `pkg-config --cflags guile-2.0` \
       -shared -o libguile-bessel.so -fPIC bessel.c

For creating shared libraries portably, we recommend the use of GNU
Libtool (see Introduction).

A shared library can be loaded into a running Guile process with the
function load-extension. The j0 is then immediately available:

     $ guile
     scheme@(guile-user)>
                 (load-extension "./libguile-bessel" "init_bessel")
     scheme@(guile-user)> (j0 2)
     $1 = 0.223890779141236


_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to