Ruby-mysql library load error

I am trying to get the ruby dbi library up and running on my machine.
Since I am using MySQL as my database server I am first trying to
install mysql-ruby. It detects the MySQL libraries fine when
configuring, and compile the library fine. When I try to run a script
that uses the library is just says “load error”.

When I run ruby in verbose mode and do nothing but try to load the
newly compiled library I get:

%> ruby -l mysql.so -v
mysql.so:1: Invalid char \177' in expression mysql.so:1: Invalid char\001’ in expression
mysql.so:1: Invalid char \001' in expression mysql.so:1: Invalid char\001’ in expression

My knowledge on ruby and libraries is a bit limited so I am not sure
where to go from here. Any suggestions?

···


Eric Anderson

Yes - read 'man ruby' :slight_smile:

       -l enables automatic line-ending processing, which means to firstly
              set $\ to the value of $/, and secondly chops every line read
              using chop!.

I don't think that's what you wanted; "mysql.so" is then being treated as a
Ruby script (text file). Try:

    ruby -r mysql

Or in irb:

    require "mysql"

Regards,

Brian.

···

On Sat, Jul 12, 2003 at 12:59:42PM +0900, Eric Anderson wrote:

When I run ruby in verbose mode and do nothing but try to load the
newly compiled library I get:

%> ruby -l mysql.so -v
mysql.so:1: Invalid char `\177' in expression
mysql.so:1: Invalid char `\001' in expression
mysql.so:1: Invalid char `\001' in expression
mysql.so:1: Invalid char `\001' in expression

My knowledge on ruby and libraries is a bit limited so I am not sure
where to go from here. Any suggestions?

As Brian Candler pointed out, what I posted is not what I meant to
post. Somehow I got my switches confused. I was trying to isolate the
script down to the smallest possible to show my problem, but got the
-l and -r switch confused ( as well as the -v and -w ). That’s what I
get for programming on a Friday night. :slight_smile:

Anway, let me try again. By running the following:

echo “puts ‘test’” | ruby -w -r mysql.so

on my new ruby-mysql library I get the following:

0: (null) - ./mysql.so (LoadError)

Is there anyway I can get more debugging information. It looks like it
is throwning some kind of load error exception. Is there anyway I can
get a message associated with that error so that I can debug why the
library is not loading?

Thanks for any information, and sorry about the last confusing post.

···


Eric Anderson

eric.anderson@sterlingpresence.com (Eric Anderson) wrote:

I am trying to get the ruby dbi library up and running on my machine.
Since I am using MySQL as my database server I am first trying to
install mysql-ruby. It detects the MySQL libraries fine when
configuring, and compile the library fine. When I try to run a script
that uses the library is just says “load error”.

When I run ruby in verbose mode and do nothing but try to load the
newly compiled library I get:

%> ruby -l mysql.so -v
mysql.so:1: Invalid char \177' in expression mysql.so:1: Invalid char \001’ in expression
mysql.so:1: Invalid char \001' in expression mysql.so:1: Invalid char \001’ in expression

My knowledge on ruby and libraries is a bit limited so I am not sure
where to go from here. Any suggestions?

I’m not certain if this is a case of the blind leading the blind
because my knowledge of ruby and libraries is equally limited but I had
a similar problem with mysql-ruby when I first started using it.

However for me,

$echo “puts ‘test’” | ruby -w -r mysql.so
test
$

works. But my original problem was similar…when I first installed and
compiled mysql-ruby, the test cases ran fine (test.rb running in the
mysql-ruby directory). Later, I had to scrap the directory and untar it
anew. Then test.rb stopped working:

$ruby test.rb localhost stephyn 0m4hhung
test.rb:11:in `require’: No such file to load – ./mysql (LoadError)
from test.rb:11
$

I inferred that the error “./mysql” meant ruby was looking for it in
the current directory by default or design, I hadn’t rebuilt mysql-ruby
so the file naturally wasn’t there and sure enough the line in test.rb
is:

require “./mysql.o”

So in that case, it was looking for it in the current directory by
design.

If you can still run test.rb from the directory where you built
mysql-ruby (probably mysql-ruby-{version #}, then perhaps the install
process failed without your knowledge or the library was not put where
it is expected (I have had this problem with some packages after
compiling them on OS X).

My equivalent of mysql.so is in:

/usr/local/lib/ruby/1.6/powerpc-darwin6.6/

it is also the directory where just about every other binary is
located. (libruby.a, socket.bundle—I guess socket.so or socket.o for
peeps on other platforms).

I would recommend searching for libruby.a and nosing around to see what
else is in there and adjoining directories.

If you can’t still run test.rb from the compilation directory, I
would start over until you can…that would limit the problem search
space.

My $0.02…maybe not even that.

Steve

(And I thought I wasn’t going to have to learn C!)

···

On Saturday, July 12, 2003, at 11:43 AM, Eric Anderson wrote:

As Brian Candler pointed out, what I posted is not what I meant to
post. Somehow I got my switches confused. I was trying to isolate the
script down to the smallest possible to show my problem, but got the
-l and -r switch confused ( as well as the -v and -w ). That’s what I
get for programming on a Friday night. :slight_smile:

Anway, let me try again. By running the following:

echo “puts ‘test’” | ruby -w -r mysql.so

on my new ruby-mysql library I get the following:

0: (null) - ./mysql.so (LoadError)

Is there anyway I can get more debugging information. It looks like it
is throwning some kind of load error exception. Is there anyway I can
get a message associated with that error so that I can debug why the
library is not loading?

Thanks for any information, and sorry about the last confusing post.


Eric Anderson

What do “file mysql.so” and “ldd mysql.so” print?

Regards,

Brian.

···

On Sun, Jul 13, 2003 at 12:43:07AM +0900, Eric Anderson wrote:

on my new ruby-mysql library I get the following:

0: (null) - ./mysql.so (LoadError)

Brian Candler B.Candler@pobox.com wrote in message news:20030712171443.GA81235@uk.tiscali.com

on my new ruby-mysql library I get the following:

0: (null) - ./mysql.so (LoadError)

What do “file mysql.so” and “ldd mysql.so” print?

%> file mysql.so
mysql.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV),
not stripped

%> ldd mysql.so
libmysqlclient.so.10 => /usr/lib/mysql/libmysqlclient.so.10
(0x40011000)
libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
libz.so.1 => /usr/lib/libz.so.1 (0x40049000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x40057000)
libnsl.so.1 => /lib/libnsl.so.1 (0x40084000)
libm.so.6 => /lib/i686/libm.so.6 (0x4009a000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

Thanks,
Eric

···

On Sun, Jul 13, 2003 at 12:43:07AM +0900, Eric Anderson wrote:

Stephyn Butcher tendzin.dorje@starpower.net wrote in message news:8BACDF74-B488-11D7-B1F0-000393A478C8@starpower.net

If you can’t still run test.rb from the compilation directory, I
would start over until you can…that would limit the problem search
space.

Thanks for trying to help, but I don’t think this is the same problem.
It finds the library, but can’t load it. Let me start from scratch:

%> ruby extconf.rb --with-mysql-include=/usr/include/mysql/
–with-mysql-lib=/usr/lib/mysql/

checking for mysql_query() in -lmysqlclient… yes
checking for mysql.h… yes
creating Makefile
cpp0: warning: changing search order for system directory
“/usr/include”
cpp0: warning: as it has already been specified as a non-system
directory

%> make
gcc -shared -L/usr/lib/mysql/ -L/usr/lib/ruby/1.6/i386-linux
-L/usr/lib -o mysql.so -L. -lruby -lmysqlclient -lc

%> echo “puts ‘test’” | ruby -w -r ./mysql.so
0: (null) - ./mysql.so (LoadError)

I just had a thought after writing this. I did a locate on mysql.so
and I noticed that the following file exists:
/usr/lib/php4/mysql.so

Could it be trying to load that even though I am specifying
“./mysql.so”. How do I change the dynamic library search path?

ruby -r /path/to/the/correct/mysql.so

or change $: - but I don’t think that’s the problem as you explicitly gave
“./” as the path.

You could try strace/truss/ktrace (depending on your OS) on ruby:

strace ruby -r ./mysql.so

which should show you what files it’s trying to access.

Regards,

Brian.

···

On Wed, Jul 16, 2003 at 01:04:05PM +0900, Eric Anderson wrote:

%> echo “puts ‘test’” | ruby -w -r ./mysql.so
0: (null) - ./mysql.so (LoadError)

I just had a thought after writing this. I did a locate on mysql.so
and I noticed that the following file exists:
/usr/lib/php4/mysql.so

Could it be trying to load that even though I am specifying
“./mysql.so”. How do I change the dynamic library search path?

HA!! I figured it out. If you look at one of my previous posts, the
makefile generated does not actually compile mysql.c. From taking a
quick look at the extconf.rb file it looks like mysql.c is generated
from mysql.c.in after the makefile is created. So mysql.c doesn’t yet
exist when the makefile is created causing the makefile to be
generated incorrectly.

A quick workaround is to run the extconf.rb script twice. This creates
a correct Makefile and compiles a library that I can include.

So now did I do something wrong on compiling this ruby module, or is
the extconf.rb script written incorrectly?

···

Brian Candler B.Candler@pobox.com wrote:

You could try strace/truss/ktrace (depending on your OS) on ruby:

strace ruby -r ./mysql.so

which should show you what files it’s trying to access.


Eric Anderson

Hi,

So now did I do something wrong on compiling this ruby module, or is
the extconf.rb script written incorrectly?

Try to move create_makefile line to the last.

And 1.8 support patch.

— extconf.rb.orig 2003-01-29 08:59:59.000000000 +0900
+++ extconf.rb 2003-07-18 13:34:30.000000000 +0900
@@ -25,18 +25,21 @@ else
exit 1
end
-create_makefile(“mysql”)

make mysql constant

-File::open(“conftest.c”, “w”) do |f|

  • f.puts src
    -end
    -cpp = Config::expand sprintf(CPP, $CPPFLAGS, $CFLAGS, ‘’)
    -unless system “#{cpp} > confout” then
  • exit 1
    +if defined?(cpp_command)
  • try_do(src, cpp_command(CPPOUTFILE))
    +else
  • File::open(“conftest.c”, “w”) do |f|
  • f.puts src
  • end
  • cpp = Config::expand sprintf(CPP, $CPPFLAGS, $CFLAGS, opt)
  • unless system(“#{cpp} > conftest.i”)
  • exit 1
  • end
    end
    File::unlink “conftest.c”

error_syms =
-IO::foreach(‘confout’) do |l|
+IO::foreach(‘conftest.i’) do |l|
next unless l =~ /errmsg.h|mysqld_error.h/
fn = l.split(/"/)[1]
@@ -47,5 +50,5 @@ IO::foreach(‘confout’) do |l|
end
end
-File::unlink ‘confout’
+rm_f ‘conftest.*’
error_syms.uniq!

@@ -59,2 +62,4 @@ IO::foreach(‘mysql.c.in’) do |l|
end
end

···

At Fri, 18 Jul 2003 13:02:29 +0900, Eric Anderson wrote:
+
+create_makefile(“mysql”)


Nobu Nakada