guile-user
[Top][All Lists]
Advanced

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

Why won't this extension load?


From: Steve Juranich
Subject: Why won't this extension load?
Date: Tue, 13 Dec 2005 09:01:43 -0700

I'm fooling around trying to learn the Guile API.  I'm following the
example in the source distribution of v1.6.7.

I've got a simple little C++ file (please try to ignore the bad style
as it's not relevant to the problem at hand) that goes like this:

<code name="test.cc">
#include <cstdio>
#include <libguile.h>

static scm_t_bits scm_tc16_point;

typedef struct {
  double x, y, z;
} point;

static SCM mark_point(SCM pt) {
  return SCM_CELL_OBJECT_1(pt);
}

static int print_point(SCM pt, SCM port, scm_print_state *pstate) {
  point *_pt = (point*) SCM_CELL_OBJECT_1(pt);

  char buf[256];
  sprintf(buf, "%f, %f, %f", _pt->x, _pt->y, _pt->z);

  scm_puts("#<point ", port);
  scm_puts(buf, port);
  scm_puts(" >", port);

  return 1;
}

static SCM make_point(void) {
  point *pt = new point;
  pt->x = 0.0;
  pt->y = 0.0;
  pt->z = 0.0;

  SCM value = SCM_PACK(pt);
  SCM newpoint;
  SCM_NEWSMOB(newpoint, scm_tc16_point, value);

  return newpoint;
}

void scm_init_test() {
  scm_tc16_point = scm_make_smob_type("point", 0);
  scm_set_smob_mark(scm_tc16_point, mark_point);
  scm_set_smob_print(scm_tc16_point, print_point);

  scm_c_define_gsubr("make-point", 0, 0, 0, make_point);
}
</code>

I compile and link the code into a shared object file using GCC via
the following commnads:

prompt$ g++ -c -o test.o test.cc
prompt$ g++ -shared -o libtest.so test.o -lguile
I then have a shiny new "libtest.so" file in my directory.

Now for the test, I start up Guile and try to load my new extension:

<guile-session>
prompt$ guile
Reading global startup file.
;;; loading /local/swl/share/guile/1.6/ice-9/format.scm
;;; loading /local/swl/share/guile/1.6/ice-9/and-let-star.scm
;;; loading /local/swl/share/guile/1.6/srfi/srfi-1.scm
;;; loading /local/swl/share/guile/1.6/ice-9/session.scm
;;; loading /local/swl/share/guile/1.6/ice-9/documentation.scm
;;; loading /local/swl/share/guile/1.6/ice-9/regex.scm
;;; loading /local/swl/share/guile/1.6/ice-9/receive.scm
;;; loading /local/swl/share/guile/1.6/ice-9/pretty-print.scm
;;; loading /local/swl/share/guile/1.6/ice-9/optargs.scm
;;; loading /local/swl/share/guile/1.6/ice-9/debug.scm
guile> (load-extension "libtest" "scm_init_test")

Backtrace:
In standard input:
   1: 0* [load-extension "libtest" "scm_init_test"]

standard input:1:1: In procedure dynamic-func in expression
(load-extension "libtest" "scm_init_test"):
standard input:1:1: ./libtest.so: undefined symbol: scm_init_test
ABORT: (misc-error)
</guile-session>

So as a sanity check I run...
prompt$ nm -C libtest.so | grep scm_init
00000b34 T scm_init_test()

I'm totally willing to accept the fact that my module has bugs, but
I'm not even getting out of the gate on this one and I'm not sure why.
 It sure looks to me (and to nm) like the symbol in question is
defined.

Can somebody please give me a clue as to what is going on?

Oh, and before somebody asks: Yes, my LD_LIBRARY_PATH has "." in it.

Thanks a bunch!
--
Steve Juranich
Tucson, AZ
USA




reply via email to

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