guile-devel
[Top][All Lists]
Advanced

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

Re: What can I do to help? (conclusions)


From: Daniel Skarda
Subject: Re: What can I do to help? (conclusions)
Date: 10 Oct 2002 14:07:23 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

> > (or link them explicitely with libstdc++). For example you do not
> > have to link guile against libgtk to make guile-gtk modules work.
> > 
> Yes, I know that. This is a completly different problem, though. It's
> not about the C++ standard lib(s), but about C++ features such as
> exceptions and RTTI that must be 'supported' by the main program
> (don't ask me for details, however).

  If you want to _throw_ C++ exception through C code, than yes - libguile has 
to
be compiled using g++. But I do not think this is a good idea - because you
bypass Guile exception mechanism and you will not be able to catch C++
exceptions from scheme and vice versa.

  Recipe I used in my app: wrap all C++ "glue" functions with try/catch and
translate C++ exceptions to Scheme. Also all C++ -> Scheme entries must be
handled and Scheme exceptions translated to C++.

  I try to extract helper code from my app and create "libguile++" library, with
utilities that are necessary for Guile/C++ integration tasks.

> >   But do not believe me, it is just a guess few minutes before midnight...
> > I have never loaded C++ modules to C program.
> > 
> I don't since I know better ;-) The proof is left as an exercise to
> the reader: Just compile some c++ code (and do some exception stuff in
> it) into a guile module, and guile will crash on loading this module -
> same thing with s/guile/c-linked-app/g.

  See the code attached bellow - I have not any problems (on Debian Linux,
that's it). So reader is confused and tomorow he is going to try some SGI/Sun
machines... :-)

0.

;--- Makefile: --------------------------------------------------------
.SUFFIXES: .lo .la

CXXFLAGS = $(shell guile-config compile)
LDFLAGS =  $(shell guile-config link) -rpath $(shell pwd)


all: libfoo.la

libfoo.la: foo.lo
        libtool --mode=link $(CXX) -o $@ $^ $(LDFLAGS) $(LIBS)


%.lo: %.cc 
        libtool --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o  $@ $<

clean:
        -rm -rvf .libs *.lo *.la *.a *.so

;--- foo.cc -------------------------------------------------------------------
#include <libguile.h>
#include <stdlib.h>

static SCM
scm_foo (void)
try
{ 
  if (random () & 1)
    throw "Something very bad happened";

  return scm_makfrom0str ("bar"); 
}
catch (const char* desc)
{ 
  scm_misc_error ("foo", desc, SCM_EOL);
  return SCM_UNSPECIFIED;
}

extern "C" 
void
init_foo (void)
{
  scm_c_define_gsubr ("foo", 0,0,0, scm_foo);
} 
;--- foo.scm ----------------------------------------------------------
(define-module (foo)
  :use-module (gtk-1.2 dynlink))

(merge-compiled-code "init_foo" "libfoo")




reply via email to

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