* Why won't this extension load?
@ 2005-12-13 16:01 Steve Juranich
2005-12-13 17:47 ` Stephen Compall
2005-12-13 17:53 ` Ken Raeburn
0 siblings, 2 replies; 4+ messages in thread
From: Steve Juranich @ 2005-12-13 16:01 UTC (permalink / 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why won't this extension load?
2005-12-13 16:01 Why won't this extension load? Steve Juranich
@ 2005-12-13 17:47 ` Stephen Compall
2005-12-14 14:23 ` Steve Juranich
2005-12-13 17:53 ` Ken Raeburn
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Compall @ 2005-12-13 17:47 UTC (permalink / raw)
Cc: Guile User List
[-- Attachment #1.1: Type: text/plain, Size: 1138 bytes --]
On Tue, 2005-12-13 at 09:01 -0700, Steve Juranich wrote:
> 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">
> void 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
> 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.
Strictly speaking, the symbol "scm_init_test" hasn't been defined, some
wacko symbol like _Nqhtjhwq_scm_init_test has been defined [well, maybe
not that bad for a function with no return value and no arguments].
Regardless, the name has been mangled by the C++ compiler, which is why
you pass the -C option to `nm', which demangles names. The solution is
to say:
extern "C"
void scm_init_test....
--
Stephen Compall
http://scompall.nocandysoftware.com/blog
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why won't this extension load?
2005-12-13 16:01 Why won't this extension load? Steve Juranich
2005-12-13 17:47 ` Stephen Compall
@ 2005-12-13 17:53 ` Ken Raeburn
1 sibling, 0 replies; 4+ messages in thread
From: Ken Raeburn @ 2005-12-13 17:53 UTC (permalink / raw)
Cc: Guile User List
On Dec 13, 2005, at 11:01, Steve Juranich wrote:
> 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:
C++ "mangles" function names to express the argument types as well.
GNU "nm -C" will reverse this, so when you see:
> So as a sanity check I run...
> prompt$ nm -C libtest.so | grep scm_init
> 00000b34 T scm_init_test()
... the symbol name in the file is *not* "scm_init_test". Run this
command without the "-C" to see what the real symbol name is.
If you add
extern "C" void scm_init_test();
before the definition I think everything will work.
Ken
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why won't this extension load?
2005-12-13 17:47 ` Stephen Compall
@ 2005-12-14 14:23 ` Steve Juranich
0 siblings, 0 replies; 4+ messages in thread
From: Steve Juranich @ 2005-12-14 14:23 UTC (permalink / raw)
On 12/13/05, Stephen Compall <s11@member.fsf.org> wrote:
> Strictly speaking, the symbol "scm_init_test" hasn't been defined, some
> wacko symbol like _Nqhtjhwq_scm_init_test has been defined [well, maybe
> not that bad for a function with no return value and no arguments].
> Regardless, the name has been mangled by the C++ compiler, which is why
> you pass the -C option to `nm', which demangles names. The solution is
> to say:
>
> extern "C"
> void scm_init_test....
Silly me. So it is. Thanks for the help.
--
Steve Juranich
Tucson, AZ
USA
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-12-14 14:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-13 16:01 Why won't this extension load? Steve Juranich
2005-12-13 17:47 ` Stephen Compall
2005-12-14 14:23 ` Steve Juranich
2005-12-13 17:53 ` Ken Raeburn
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).