lilypond-devel
[Top][All Lists]
Advanced

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

Does the LilyPond build generate shared libraries you can use with Guile


From: Ian Hulin
Subject: Does the LilyPond build generate shared libraries you can use with Guile (load-extension) ?
Date: Mon, 24 Oct 2011 18:29:13 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1

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




reply via email to

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