Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues building mysql gem in ruby 2.0.0 in Windows #23

Closed
bapti opened this issue Jul 16, 2013 · 13 comments
Closed

Having issues building mysql gem in ruby 2.0.0 in Windows #23

bapti opened this issue Jul 16, 2013 · 13 comments

Comments

@bapti
Copy link

bapti commented Jul 16, 2013

I've documented the issue in this SO question http://stackoverflow.com/questions/17673612/installing-mysql-ruby-gem-in-windows-fails-using-ruby-2-0-0

However here's a quick overview - I'm running the following command from the tutorial http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/

gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

I get the following error

This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

C:/ruby200/bin/ruby.exe extconf.rb --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32 --with-mysql-lib=C:\mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll
checking for main() in -llibmysql... no
*** extconf.rb failed ***

I'm not quite sure what i'm doing wrong here.

@luislavena
Copy link
Owner

Looks like, by the configure options given: --with-mysql-lib=C:\mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll is incorrect.

The option --with-mysql-lib is to indicate a lib directory and not a DLL, by using --with-mysql-dir is enough as it implies both include and lib definitions.

Please see again my blog article about the usage options.

@bapti
Copy link
Author

bapti commented Jul 17, 2013

Hi, sorry I copied the output from the wrong window, I was trying other options.

Entering the following command with only the --with-mysql-dir option

gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

It fails to build

Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32'
This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

C:/ruby200/bin/ruby.exe extconf.rb --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
...

Perhaps it's something wrong with my environment that's causing the failure.

I'm using Windows 7 64bit if that makes any difference.

@luislavena
Copy link
Owner

Hello, for extconf process not detecting the mysql lib could only happen if the version of ruby you're using differs in bits from the library you extracted.

Are you trying ruby 2.0.0 x64? I don't see specifics of the version your using (ruby --version can tell us that)

Can you confirm which version of ruby and which version of devkit you are using?

Thank you

@bapti
Copy link
Author

bapti commented Jul 17, 2013

ruby --version gives ruby 2.0.0p247 (2013-06-27) [i386-mingw32]

The ruby devkit was installed from chocolatey http://chocolatey.org/packages/ruby.devkit Ruby DevKit 4.5.2.20111230

Hope that helps

@luislavena
Copy link
Owner

@bapti can you look for mkmf.log file inside the gem directory reported by RubyGems as failure and paste the contents here?

I would like to look at what is reporting as problem by GCC.

Thank you.

@bapti
Copy link
Author

bapti commented Jul 17, 2013

Here you are, it's a bit of an epic

have_library: checking for main() in -llibmysql... -------------------- no

"gcc -o conftest.exe -IC:/ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/ruby200/include/ruby-2.0.0/ruby/backward -IC:/ruby200/include/ruby-2.0.0 -I. -IC:/mysql-connector-c-noinstall-6.0.2-win32/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/ruby200/lib -LC:/mysql-connector-c-noinstall-6.0.2-win32/ -L.      -lmsvcrt-ruby200  -lshell32 -lws2_32 -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

"gcc -o conftest.exe -IC:/ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/ruby200/include/ruby-2.0.0/ruby/backward -IC:/ruby200/include/ruby-2.0.0 -I. -IC:/mysql-connector-c-noinstall-6.0.2-win32/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/ruby200/lib -LC:/mysql-connector-c-noinstall-6.0.2-win32/ -L.      -lmsvcrt-ruby200 -llibmysql  -lshell32 -lws2_32 -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:8:57: error: 'main' undeclared (first use in this function)
conftest.c:8:57: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
 9: int main(int argc, char **argv)
10: {
11:   if (argc > 1000000) {
12:     printf("%p", &t);
13:   }
14: 
15:   return 0;
16: }
/* end */

"gcc -o conftest.exe -IC:/ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/ruby200/include/ruby-2.0.0/ruby/backward -IC:/ruby200/include/ruby-2.0.0 -I. -IC:/mysql-connector-c-noinstall-6.0.2-win32/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/ruby200/lib -LC:/mysql-connector-c-noinstall-6.0.2-win32/ -L.      -lmsvcrt-ruby200 -llibmysql  -lshell32 -lws2_32 -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:8:1: warning: implicit declaration of function 'main'
conftest.c:11:6: warning: 'argc' is used uninitialized in this function
conftest.c:8:5: note: 'argc' was declared here
c:/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int t(void) { main(); return 0; }
 9: int main(int argc, char **argv)
10: {
11:   if (argc > 1000000) {
12:     printf("%p", &t);
13:   }
14: 
15:   return 0;
16: }
/* end */

--------------------

@luislavena
Copy link
Owner

@bapti thank you.

It is interesting it cannot find libmysql since the file should be in the lib folder of the extracted connector.

Can you confirm the contents of the connector you extracted? specifically the contents of lib and include directories.

@luislavena luislavena reopened this Jul 17, 2013
@bapti
Copy link
Author

bapti commented Jul 17, 2013

It does seem really odd, I extracted the folder from the 6.0.2 download linked in the blog article, or related SO question, I can't remember exactly. I managed to get the mysql2 gem to install in a similar fashion with something like gem install mysql2 --platform=ruby --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32 and then made a connection to the database that I needed to.

Lib folder
mysql-lib-folder

Include folder
mysql-include-folder

Bin folder for good measure
mysql-bin-folder

@luislavena
Copy link
Owner

@bapti can you try the following two options?

Option 1:

gem install mysql --platform=ruby -- --with-opt-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

That should use that directory too.

Option 2: break down directories:

gem install mysql --platform=ruby -- --with-mysql-include=C:/mysql-connector-c-noinstall-6.0.2-win32/include --with-mysql-lib=C:/mysql-connector-c-noinstall-6.0.2-win32/lib

Please try each one of the scenarios and let's see the contents of mkmf.log for each one.

Thank you and really sorry the inconveniences.

@bapti
Copy link
Author

bapti commented Jul 18, 2013

Hi Luis, the installation worked with option 1, thanks for all your help!!

gem install mysql --platform=ruby -- --with-opt-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

@bapti
Copy link
Author

bapti commented Jul 18, 2013

The successful log

mysql-success

@luislavena
Copy link
Owner

@bapti great to hear!

I will recommend moving on to use --with-opt-dir instead.

Will update my blog post to avoid others suffering the same fate 😢

Closing this now.

Thank you for your patience and help figuring this out!

@LellaKS
Copy link

LellaKS commented Jan 23, 2017

Not able to mysql gem in ruby 2.3.3 version. My ruby version :ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]. Getting below exception:
C:\Ruby23-x64>gem install mysql
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

current directory: C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mysql-2.9.1/ext/mysql_api

C:/Ruby23-x64/bin/ruby.exe -r ./siteconf20170123-7004-xoua5t.rb extconf.rb
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby23-x64/bin/$(RUBY_BASE_NAME)
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-libmysqllib
--without-libmysqllib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

C:/Ruby23-x64/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/mysql-2.9.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mysql-2.9.1 for inspection.
Results logged to C:/Ruby23-x64/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/mysql-2.9.1/gem_make.out

######Attaching gem_make.out and mkmf.log file.
gem_makeout.txt
mkmflog.txt
MY devkit version : DevKit-mingw64-64-4.7.2-20130224-1432-sfx
Would you please help me to resolve the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants