0

I want to embed guile in a c++ application, but I get "undefined reference" errors when I try to compile: Ubuntu 12.04 guile-1.8.8

If I compile the example from the guile docs

gcc -o guile-test `pkg-config guile-1.8 --cflags` `pkg-config guile-1.8 --libs` guile-test.c

on the console, it aborts with errors:

/tmp/ccHZCHNL.o: In function `inner_main':
guile-test.c:(.text+0x14): undefined reference to `scm_shell'
/tmp/ccHZCHNL.o: In function `main':
guile-test.c:(.text+0x41): undefined reference to `scm_boot_guile'
collect2: ld gab 1 als Ende-Status zurück

If I compile some example.so (including "libguile.h") to embed in guile, all is working as expected.

Does anybody know, what might cause this error?

Best, Jan-Peter

  • Note that I would very highly recommend moving to Guile 2.x - it's both considerably faster and has much more reliable string handling in the C interface (with `scm_from_utf8_string()` etc.) – Peter T.B. Brett Mar 14 '14 at 08:22
  • I would think of it, but I am waiting for lilypond moving to guile 2, which is hopefully going to happen this year. – Jan-Peter Voigt Mar 14 '14 at 12:50

1 Answers1

1

Yes. You didn't follow their build instructions correctly. :-) In particular, you need to specify link dependencies after the dependent objects. Try this instead:

gcc -o guile-test `pkg-config guile-1.8 --cflags` guile-test.c `pkg-config guile-1.8 --libs`

In particular, the libraries need to be listed after all the objects that use them, such as guile-test.c.

(By the way, this isn't Guile-specific. The standard linker always expects this ordering.)

C. K. Young
  • 219,335
  • 46
  • 382
  • 435