# Building mysql extension/gem with MinGW (was Re: Gem build issues Ubuntu 9.10 64 bit)

**URL:** <https://www.ruby-forum.com/t/building-mysql-extension-gem-with-mingw-was-re-gem-build-issues-ubuntu-9-10-64-bit/181636>\
**Category:** Ruby\
**Created:** [January 15, 2010, 1:12am UTC](https://www.ruby-forum.com/t/building-mysql-extension-gem-with-mingw-was-re-gem-build-issues-ubuntu-9-10-64-bit/181636 "2010-01-15T01:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericrchr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@ericrchr](https://www.ruby-forum.com/u/ericrchr)\
**Post date:** [January 15, 2010, 1:12am UTC](https://www.ruby-forum.com/t/building-mysql-extension-gem-with-mingw-was-re-gem-build-issues-ubuntu-9-10-64-bit/181636/1 "2010-01-15T01:12:09Z")

</div>

On Thu, Jan 14, 2010 at 5:26 PM, Eric C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > On Jan 13, 10:36 pm, Dale A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > No definition for field\_name  
> > > Luis L.

Ugh, I top-posted AND forgot to change the subject line. Sorry!

---

<div class="post-metadata">

**Author:** ![ericrchr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@ericrchr](https://www.ruby-forum.com/u/ericrchr)\
**Post date:** [January 15, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/building-mysql-extension-gem-with-mingw-was-re-gem-build-issues-ubuntu-9-10-64-bit/181636/2 "2010-01-15T21:07:31Z")

</div>

On Jan 14, 9:11 pm, Eric C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Since people are talking about the mysql gem, I thought I’d ask how  
> > you can build it under MinGW. I can’t seem to make any combination of  
> > extconf switches work.

–with-mysql-dir is the only switch that you need, or --with-mysql-  
include and --with-mysql-lib

> > I have the standard Windows mysql-5.1.42-win32 installed in  
> > /usr/local/mysql. Do I need some MinGW-specific version? (I’ve tried  
> > compiling it from source with MSYS/MinGW and also Cygwin, with no  
> > success.)

You’re talking about RubyInstaller and combined with DevKit, correct?

If so, then don’t install form inside bash or use \*nix like paths.

If you have MySQL 5.1, you need:

1. RubyInstaller 1.9.1 installed
2. DevKit installed and configured (edit fstab as indicated in the  
wiki)

[http://wiki.github.com/oneclick/rubyinstaller/development-kit](http://wiki.github.com/oneclick/rubyinstaller/development-kit)

1. From a Windows prompt, ensure Ruby and GCC works:

ruby -v  
gcc --version

1. Have MySQL installed and know the path where its library is. If you  
manually extracted it form the zip, remember the location.

2. proceed to gem installation and indicate the “ruby” platform to  
force the compilation. Now use the path to MySQL

gem install mysql --platform ruby – --with-mysql-include=C:/mysql/  
include --with-mysql-lib=C:/mysql/lib/opt

I’ve indicated “opt” as library because is the "opt"imized version.

Please note that extracting or installing MySQL or Ruby or gems in a  
path with spaces can be a problem. Try avoiding them to all cost.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![ericrchr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@ericrchr](https://www.ruby-forum.com/u/ericrchr)\
**Post date:** [January 16, 2010, 1:30am UTC](https://www.ruby-forum.com/t/building-mysql-extension-gem-with-mingw-was-re-gem-build-issues-ubuntu-9-10-64-bit/181636/3 "2010-01-16T01:30:21Z")

</div>

On Fri, Jan 15, 2010 at 2:05 PM, Luis L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> include and --with-mysql-lib  
> OK. Using the instructions below, just --with-mysql-dir doesn’t quite  
> work (perhaps because the libs aren’t right in lib/), but -include  
> with -lib works.

> > > I have the standard Windows mysql-5.1.42-win32 installed in  
> > > /usr/local/mysql. Do I need some MinGW-specific version? (I’ve tried  
> > > compiling it from source with MSYS/MinGW and also Cygwin, with no  
> > > success.)
> 
> You’re talking about RubyInstaller and combined with DevKit, correct?
> 
> If so, then don’t install form inside bash or use \*nix like paths.

Ah, yes. OK.

> include --with-mysql-lib=C:/mysql/lib/opt
> 
> I’ve indicated “opt” as library because is the "opt"imized version.
> 
> Please note that extracting or installing MySQL or Ruby or gems in a  
> path with spaces can be a problem. Try avoiding them to all cost.
> 
> Hope that helps.

Yes, that allows me to build the gem with no problems.

However, I would still like to build from the tarball (since I am  
working on a modified version of it). I used this command line to find  
out what exact steps gem was taking:

```
gem install mysql --verbose --platform ruby --

```

–with-mysql-include=C:/MySQL/include  
–with-mysql-lib=C:/MySQL/lib/opt

That showed, as expected, that the extconf command line is:

```
C:/Ruby/bin/ruby.exe extconf.rb

```

–with-mysql-include=C:/MySQL/include --with-mysq  
l-lib=C:/MySQL/lib/opt

But when I issue this command myself in the source directory, extconf  
fails to find mysql\_query. What am I doing wrong? I am using cmd.exe  
for both, and my environment should be the same. I wonder if gem has  
its own environment that it passes to ruby/extconf.

---

<div class="post-metadata">

**Author:** ![ericrchr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@ericrchr](https://www.ruby-forum.com/u/ericrchr)\
**Post date:** [January 16, 2010, 5:16pm UTC](https://www.ruby-forum.com/t/building-mysql-extension-gem-with-mingw-was-re-gem-build-issues-ubuntu-9-10-64-bit/181636/4 "2010-01-16T17:16:39Z")

</div>

On Fri, Jan 15, 2010 at 6:29 PM, Eric C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > –with-mysql-dir is the only switch that you need, or --with-mysql-
> > 
> > > > success.)
> > 
> > You’re talking about RubyInstaller and combined with DevKit, correct?
> > 
> > If so, then don’t install form inside bash or use \*nix like paths.
> 
> Ah, yes. OK.

I just discovered that building the gem actually works fine in MSYS  
also; and I can either use DOS-style or Unix-style pathnames for the  
MySQL directories.

> > 1. From a Windows prompt, ensure Ruby and GCC works:  
> > gem install mysql --platform ruby – --with-mysql-include=C:/mysql/
> 
> C:/Ruby/bin/ruby.exe extconf.rb  
> –with-mysql-include=C:/MySQL/include --with-mysq  
> l-lib=C:/MySQL/lib/opt
> 
> But when I issue this command myself in the source directory, extconf  
> fails to find mysql\_query. What am I doing wrong? I am using cmd.exe  
> for both, and my environment should be the same. I wonder if gem has  
> its own environment that it passes to ruby/extconf.

I’m still trying to figure out this aspect of the problem. At least  
compiling the extension through gem fixed a bug I saw with the binary  
gem – before, the query method always failed, saying it was not  
connected, even though I had connected successfully (as demonstrated  
by #list\_dbs and #list\_tables).

OT: I’m just starting to use Gmail for mailing lists. I notice that it  
keeps incorrectly considering some of my original text as quotations,  
while some quotations it doesn’t detect as such. Is there any way to  
fix that?
