unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Steve Juranich <sjuranic@gmail.com>
Subject: Why won't this extension load?
Date: Tue, 13 Dec 2005 09:01:43 -0700	[thread overview]
Message-ID: <56190b6c0512130801y48c5bacbq6a32ff0da29bbff4@mail.gmail.com> (raw)

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


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


             reply	other threads:[~2005-12-13 16:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-13 16:01 Steve Juranich [this message]
2005-12-13 17:47 ` Why won't this extension load? Stephen Compall
2005-12-14 14:23   ` Steve Juranich
2005-12-13 17:53 ` Ken Raeburn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56190b6c0512130801y48c5bacbq6a32ff0da29bbff4@mail.gmail.com \
    --to=sjuranic@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).