M
Matthew Miller
Hello,
I'm having some trouble with my first C++ extension for Ruby. The extension
is a wrapper for the id3lib library providing my own interface over top that
of the library. I've encountered two problems, one on the build side of
things and anther from within Ruby when I tried to test the extension.
To create the makefile for the extension I'm using the 'mkmf'
module. Because the extension relies on libid3.so I tried to test for that
library using :have_library, but I've not been able to supply a second
argument that will cause the method to return true. Here is what I tried:
require 'mkmf'
if have_library( "id3", "ID3_Tag::ID3_Tag" ) then
create_makefile("id3lib")
else
puts "libid3 not found."
end
I think the trouble is that all of the symbol names in the library are
mangled by the C++ compiler. Though, even when I substitute a mangled name
for the second argument the test fails. I've gotten around this by not doing
a library test and just calling create_makefile and then editing the
resulting makefile by hand to have the extension .so linked against
libid3.so.
I looked at the FXRuby source, but it uses a different build method than
mkmf and I don't know of any other extensions that use C++ libraries. Should
I try a different build method? (Can someone recommend one?)
The second problem came up when I tried to test the extension. After
creating a new ID3Lib object, which opens an mp3 file, the script calls the
:artist method to return a string containing the value of that tag. That
method call generates an ArgumentError exception with the error message
"NULL pointer given".
I've tried to isolate where that error is generated and I can only say that
it seems to come from within Ruby. Replacing the body of the C++ function,
that is called for the no argument version of :artist, with a statement to
return a Fixnum still results in the "NULL pointer given" exception. So it
seems that the statements within id3_get_album() don't cause the exception,
but maybe someother part of my C++ code is the problem?
For people who may know more about this and need to look at the code it can
be gotten here: http://roland.sw.edu/matthew/id3lib_ext.tar.gz If for some
reason that hostname doesn't resolve (as seems to happen outside our
college) then substitute the IP address 164.106.190.246 for the hostname.
If anyone can help, I would be very appreciative. If you look at the code, I
am also open to comments and suggestions not related to the above problems.
Thanks for your help, Matthew.
I'm having some trouble with my first C++ extension for Ruby. The extension
is a wrapper for the id3lib library providing my own interface over top that
of the library. I've encountered two problems, one on the build side of
things and anther from within Ruby when I tried to test the extension.
To create the makefile for the extension I'm using the 'mkmf'
module. Because the extension relies on libid3.so I tried to test for that
library using :have_library, but I've not been able to supply a second
argument that will cause the method to return true. Here is what I tried:
require 'mkmf'
if have_library( "id3", "ID3_Tag::ID3_Tag" ) then
create_makefile("id3lib")
else
puts "libid3 not found."
end
I think the trouble is that all of the symbol names in the library are
mangled by the C++ compiler. Though, even when I substitute a mangled name
for the second argument the test fails. I've gotten around this by not doing
a library test and just calling create_makefile and then editing the
resulting makefile by hand to have the extension .so linked against
libid3.so.
I looked at the FXRuby source, but it uses a different build method than
mkmf and I don't know of any other extensions that use C++ libraries. Should
I try a different build method? (Can someone recommend one?)
The second problem came up when I tried to test the extension. After
creating a new ID3Lib object, which opens an mp3 file, the script calls the
:artist method to return a string containing the value of that tag. That
method call generates an ArgumentError exception with the error message
"NULL pointer given".
I've tried to isolate where that error is generated and I can only say that
it seems to come from within Ruby. Replacing the body of the C++ function,
that is called for the no argument version of :artist, with a statement to
return a Fixnum still results in the "NULL pointer given" exception. So it
seems that the statements within id3_get_album() don't cause the exception,
but maybe someother part of my C++ code is the problem?
For people who may know more about this and need to look at the code it can
be gotten here: http://roland.sw.edu/matthew/id3lib_ext.tar.gz If for some
reason that hostname doesn't resolve (as seems to happen outside our
college) then substitute the IP address 164.106.190.246 for the hostname.
If anyone can help, I would be very appreciative. If you look at the code, I
am also open to comments and suggestions not related to the above problems.
Thanks for your help, Matthew.