do_mysql 2.3 Install problems on OS X - tips to get the gem to build

31 views
Skip to first unread message

EvilMartini

unread,
Feb 12, 2008, 2:48:30 AM2/12/08
to DataMapper
I had a bit of a problem installing do_mysql on my OS X tiger
installation, I didn't have time to do a full forensic dissection of
the problem, but it looks like everything was related to (1) having
installed mysql into a location other and /usr/local/mysql and (2) a
missing typedef(?) in the mysql_c.c file.

Sorry for the absence of patches, I'm just posting this as a possible
resource for anyone else who might have a similar problem getting the
gem to build and install correctly. Also - this was a quick write up
that was checked but is far from edited. Just some notes that got
things working for myself:



Getting datamapper installed was a challenge for me. This is a write
up of most of the steps I took to get it compiled correctly; I'm
pretty certain that there are some extra steps in here. Indeed, I
think knowing what I now know is the problem, the correct (and shorter
method) would be to download the gem;
untar the gem to a directory; unzip the data.tar.gz file; make the
changes to this gem; retar the gem and install that version. I
haven't however tried this yet.

The only relevant thing I can mention is that I'm currently on OS X
10.4.x

YMMV - read this through and see if there's something that might help,
but I'm not responsible for any damage you do to your machine or your
psyche.

The hack^H^H^H^H - um - process that 'worked' for me:

install data_mapper

Now, the long version - install do_mysql, watch it fail miserably

Before going through this pain make certain that the mysql_config
binary can be found on your path. It's located in the bin directory
of where ever MySQL is installed. At a command prompt type:

which mysql_config

You should get a path pack, if you get "mysql_configs not found" then
it's likely that the path to the mysql bin directory isn't in your
path statement. Append the directory to your path (assuming a bash
type shell)

export PATH=$PATH:/usr/local/mysql/bin

Don't forget to

At this point the creation of the makefile might very well have
failed. If it did fail then try running ruby with a command line
like:

Getting the Makefile

ruby extconf.rb install do_mysql -- --with-mysql-bin-dir=/usr/local/
mysql/bin --with-mysql-include=/usr/local/mysql/include/mysql --with-
mysql-lib=/usr/local/mysql/lib/mysql

Don't forget to replace the directories in that path with the ones for
your mysql installation.

If you're still getting failures at this point you might have to edit
the extconf.rb file to get the right paths; the script creates a
symlink to your mysql lib files.

(It may or may not make a difference: my MySQL is actually installed
in /opt/local/mysql - but it would seem that there are several
hardcoded references to the /usr/local/mysql directory I created two
symlinks:

ln - s /opt/local/mysql /usr/local/mysql-5.0.45-osx10.4-i686
ln - s /opt/local/mysql /usr/local/mysql

I don't think that these are necessary to get the other steps to work,
but they did eliminate some problems that I was seeing with path
issues to libraries. But this document *is* describing a voodoo
ritual and as such these steps could help the mojo.

)

You should then see:

checking for mysql_query() in -lmysqlclient... yes
creating Makefile

Odds are something will fail miserably, there will be a warning that
tells you the results of the build were placed in file gem_make.out
some directory like (/usr/local/lib/ruby/gems/1.8/gems/do_mysql-0.2.3/
ext)


Fixing the Compile Step

Check the ext directory, if you have a Makefile, then the extconf.rb
file ran correctly - if not, then the extconf.rb file probably
couldn't find your mysql header files and libs . Run

sudo make clean
sudo make all

This will likely fail.

You should have a gem_make.out file that contains all sorts of helpful
information. My file was located in /usr/local/lib/ruby/gems/1.8/gems/
do_mysql-0.2.3/ext . The first time you run make, you *might* have
missing path error. Read the gem_make.out file and see if there's
something that looks like the complier can't find the libs. A quick
way to check is to make sure that the -I on the gcc command line
includes the directory for your mysql includes. Edit the mysql_c.i
file . There's a line that looks something like

%include "/usr/local/mysql-5.0.45-osx10.4-i686/include/mysql.h"

Instead of editing this line to reflect the path to the mysql libs, I
just cheated and created a symlink to as indicated earlier.

sudo make clean
sudo make all

This should fail again, but with different errors:

gem_make.out

make
gcc -I. -I. -I/usr/local/lib/ruby/1.8/i686-darwin8.11.1 -I. -I/usr/
local/mysql/include/mysql -fno-common -g -O2 -fno-common -pipe -fno-
common -Wall -c mysql_c.c
mysql_c.c: In function ‘_wrap_MYSQL_connector_fd_set’:
mysql_c.c:4264: error: ‘gptr’ undeclared (first use in this
function)
mysql_c.c:4264: error: (Each undeclared identifier is reported
only once
mysql_c.c:4264: error: for each function it appears in.)
mysql_c.c:4264: error: parse error before ‘arg2’
mysql_c.c:4283: error: ‘arg2’ undeclared (first use in this
function)
mysql_c.c:4287: error: parse error before ‘char’
mysql_c.c:4286: warning: unused variable ‘size’
mysql_c.c: In function ‘_wrap_MYSQL_connector_fd_get’:
mysql_c.c:4302: error: ‘gptr’ undeclared (first use in this
function)
mysql_c.c:4302: error: parse error before ‘result’
mysql_c.c:4315: error: ‘result’ undeclared (first use in this
function)
mysql_c.c: In function
‘_wrap_MYSQL_METHODS_advanced_command_set’:
mysql_c.c:13715: warning: assignment from incompatible pointer
type
make: *** [mysql_c.o] Error 1

Make a note of the cause of the failure - in my case there is a
missing symbol that creeps in around line 4264. Fire up your favorite
editor and head over to the offending line in mysql_c.c (which should
be in the ext subdirectory of where your gem is being built) I needed
to insert the following to get everything happy:

/* HACK - gptr is causing failure */
typedef void* gptr;

Then another round with make:

sudo make clean
sudo make all

If you only get warnings you should be good to go. At this point,
the following files should be in the ext directory:

Makefile, extconf.rb, gem_make.out, mysql_c.bundle, mysql_c.c,
mysql_c.i, mysql_c.o

You need to copy the mysql_c.bundle file to the lib directory for the
gem.

# Assuming you're in the gem's ext directory
sudo cp mysql_c.bundle ../lib

We're almost there.

Creating the gemspec

Now we have to tell the ruby gems system that we've installed the
gem. Head over to your gem's specifications directory (mine is at /
usr/local/lib/ruby/gems/1.8/specifications)

sudo touch do_mysql-0.2.3.gemspec

Edit the do_mysql-0.2.3.gemspec to contain the following information:

Gem::Specification.new do |s|
s.name = %q{do_mysql}
s.version = "0.2.3"
s.date = %q{2008-01-01}
s.summary = %q{A DataObject.rb driver for mysql - N.B.! patched
with some workarounds}
s.email = %q{wyc...@gmail.com}
s.homepage = %q{http://dataobjects.devjavu.com}
s.description = %q{A DataObject.rb driver for mysql}
s.autorequire = %q{do_mysql}
s.has_rdoc = true
s.authors = ["Yehuda Katz"]
s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/
do_mysql.rb","ext/extconf.rb", "ext/mysql_c.c", "ext/mysql_c.i"]
s.extra_rdoc_files = ["README", "LICENSE", "TODO"]
s.extensions = ["ext/extconf.rb"]
s.add_dependency(%q<data_objects>, ["> 0.0.0"])

It's probably a good idea to change the summary to something that will
remind you that the version of your library is hacked.

At this point you should be able to drop into IRB and require the
files.

NickD

unread,
Feb 12, 2008, 9:42:34 AM2/12/08
to DataMapper
I had a lot of trouble installing do_mysql as well on os x 10.5 and
10.4 (two difference machines). Although many of you may not have
this luxury ... I was able to avoid similar steps by installing
mysql-5.0.51a (the binary release for os x). It seemed that all the
mysql_c.c problems were from it not matching with the lib files from
newer OR older versions of mysql. I first tried with mysql-5.1 on OS
X 10.5 and just couldn't get it to work. On my second machine i had a
earlier version of mysql-5.0 running on OS X 10.4 and also couldn't
get it to work, but once I installed the mysql-5.0.51a I was able to
install do_mysql on both machines successfully with a one liner:

"gem install do_mysql -- --with-mysql-dir=/usr/local/mysql"

and it installed successfully.

- Nick
> mysql_c.c: In function '_wrap_MYSQL_connector_fd_set':
> mysql_c.c:4264: error: 'gptr' undeclared (first use in this
> function)
> mysql_c.c:4264: error: (Each undeclared identifier is reported
> only once
> mysql_c.c:4264: error: for each function it appears in.)
> mysql_c.c:4264: error: parse error before 'arg2'
> mysql_c.c:4283: error: 'arg2' undeclared (first use in this
> function)
> mysql_c.c:4287: error: parse error before 'char'
> mysql_c.c:4286: warning: unused variable 'size'
> mysql_c.c: In function '_wrap_MYSQL_connector_fd_get':
> mysql_c.c:4302: error: 'gptr' undeclared (first use in this
> function)
> mysql_c.c:4302: error: parse error before 'result'
> mysql_c.c:4315: error: 'result' undeclared (first use in this
> function)
> mysql_c.c: In function
> '_wrap_MYSQL_METHODS_advanced_command_set':

EvilMartini

unread,
Feb 13, 2008, 12:07:54 AM2/13/08
to DataMapper
This make some sense.

I originally used mysql-5.0.18, then thought that the libs might have
been out of date then built from source v 5.0.45. I didn't use the
binary installer. Should have mentioned that in my original post.

-- Randall

Sam Smoot

unread,
Feb 13, 2008, 2:24:33 PM2/13/08
to DataMapper
Gah! So yeah, this is being worked on right now, paring down the SWIG
to just the API we're actually using, which should be pretty stable
(hasn't changed in a few major revisions) and avoid version issues
like this.

Look for DO 1.0 by around the end of the month hopefully.

sideshow

unread,
Apr 2, 2008, 12:36:22 AM4/2/08
to DataMapper
Nick,
I think perhaps you did something else without knowing to get this
working as i have tiger / 5.0.51a mysql and this method doesnt work,
also a full uninstall / reinstall did not work using this method
cheers

sideshow

unread,
Apr 2, 2008, 3:21:53 AM4/2/08
to DataMapper
This may save someone hours!
Dont Use the MySQL binary from mysql.com it either doesnt install the
correct libs/src files or installs them wrong.
I played around for hours trying to manually install the gem on tiger
Xserve G5 setting all the flags /lib directories etc....

Save yourself the headache and follow this simple brilliant tutorial

http://hivelogic.com/articles/installing-mysql-on-mac-os-x/

then :

sudo gem install do_mysql

no flags or config options needed :)
Reply all
Reply to author
Forward
0 new messages