# Ruby-mysql library load error

**URL:** <https://rubytalk.org/t/ruby-mysql-library-load-error/6820>\
**Category:** ruby-talk\
**Created:** [12 July 2003 03:59 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820 "2003-07-12T03:59:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Anderson](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Eric\_Anderson](https://rubytalk.org/u/Eric_Anderson)\
**Post date:** [12 July 2003 03:59 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/1 "2003-07-12T03:59:42Z")

</div>

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](http://mysql.so) -v  
[mysql.so:1](http://mysql.so:1): Invalid char `\177' in expression mysql.so:1: Invalid char`\001’ in expression  
[mysql.so:1](http://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

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [12 July 2003 08:54 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/2 "2003-07-12T08:54:43Z")

</div>

Yes - read 'man ruby' 🙂

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

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

&nbsp;&nbsp;&nbsp;&nbsp;ruby -r mysql

Or in irb:

&nbsp;&nbsp;&nbsp;&nbsp;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?

---

<div class="post-metadata">

**Author:** ![Eric\_Anderson](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Eric\_Anderson](https://rubytalk.org/u/Eric_Anderson)\
**Post date:** [12 July 2003 15:43 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/3 "2003-07-12T15:43:07Z")

</div>

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. 🙂

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](mailto: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?

---

<div class="post-metadata">

**Author:** ![Stephyn\_Butcher](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Stephyn\_Butcher](https://rubytalk.org/u/Stephyn_Butcher)\
**Post date:** [12 July 2003 16:47 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/4 "2003-07-12T16:47:41Z")

</div>

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. 🙂
> > 
> > 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

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [12 July 2003 17:11 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/5 "2003-07-12T17:11:29Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Eric\_Anderson](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Eric\_Anderson](https://rubytalk.org/u/Eric_Anderson)\
**Post date:** [16 July 2003 04:03 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/6 "2003-07-16T04:03:52Z")

</div>

Brian Candler [B.Candler@pobox.com](mailto:B.Candler@pobox.com) wrote in message news:[20030712171443.GA81235@uk.tiscali.com](mailto: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:

---

<div class="post-metadata">

**Author:** ![Eric\_Anderson](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Eric\_Anderson](https://rubytalk.org/u/Eric_Anderson)\
**Post date:** [16 July 2003 04:04 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/7 "2003-07-16T04:04:05Z")

</div>

Stephyn Butcher [tendzin.dorje@starpower.net](mailto:tendzin.dorje@starpower.net) wrote in message news:[8BACDF74-B488-11D7-B1F0-000393A478C8@starpower.net](mailto: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?

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [16 July 2003 07:59 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/8 "2003-07-16T07:59:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Eric\_Anderson](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Eric\_Anderson](https://rubytalk.org/u/Eric_Anderson)\
**Post date:** [18 July 2003 04:02 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/9 "2003-07-18T04:02:29Z")

</div>

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](mailto: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

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [18 July 2003 04:39 UTC](https://rubytalk.org/t/ruby-mysql-library-load-error/6820/10 "2003-07-18T04:39:06Z")

</div>

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
