Linking Ruby to C++ via SWIG in Cygwin: missing ruby.o

I don’t know where the problem is, whether my Ruby installation or SWIG
installation, but I think it’s ruby. I’m trying to link a program
involving SWIG-generated C code and I’m getting the error, cannot
find -lruby.
If I drop the -lruby, I get these errors:

example_wrap.o(.text+0x351):example_wrap.c: undefined reference to
_rb_define_m odule' example_wrap.o(.text+0x3c7):example_wrap.c: undefined reference to_rb_cObject’

So I think I’m missing ruby.o. But why, and where can I get it?
I downloaded and extracted this, which didn’t include such a file.

http://www.ruby-lang.org/~eban/ruby/binaries/cygwin/ruby-1.6.8-20030213-i386
-cygwin.tar.gz

Hi,

···

At Sun, 16 Feb 2003 05:06:09 +0900, Alan Baljeu wrote:

I don’t know where the problem is, whether my Ruby installation or SWIG
installation, but I think it’s ruby. I’m trying to link a program
involving SWIG-generated C code and I’m getting the error, cannot
find -lruby.

You should have usr/local/lib/libcygwin-ruby16.dll.a, so
LDFLAGS has to contain

-L${RUBY}/usr/local/lib -lcygwin-ruby16

Apparently, something wrong in SWIG.


Nobu Nakada

Thanks, that was the clue I needed. This commandline works.

gcc -shared example.o example_wrap.o
/usr/local/lib/libcygwin-ruby16.dll.a -o example.so

Now, a bit off topic for this forum, but this doesn’t work, and I don’t know
the cure:

gcc -shared example.o example_wrap.o -L/usr/local/lib/
-llibcygwin-ruby16.dll.a -o example.so

You should have usr/local/lib/libcygwin-ruby16.dll.a, so
LDFLAGS has to contain

-L${RUBY}/usr/local/lib -lcygwin-ruby16
And I don’t understand how or why you strip off the preceeding ‘lib’ and
trailing ‘.dll.a’, especially since it doesn’t work.

Alan

Hi,

···

At Sun, 16 Feb 2003 11:15:05 +0900, Alan Baljeu wrote:

You should have usr/local/lib/libcygwin-ruby16.dll.a, so
LDFLAGS has to contain

-L${RUBY}/usr/local/lib -lcygwin-ruby16
And I don’t understand how or why you strip off the preceeding ‘lib’ and
trailing ‘.dll.a’, especially since it doesn’t work.

Because it is how -l option for ld works. -l$(LIB) directs ld
to search lib$(LIB).a in traditional UNIX, and cygwin ld
searches lib$(LIB).dll.a too. So you must not add preceeding
‘lib’ and trailing ‘.dll.a’.


Nobu Nakada