我无法在Windows7 x64系统中安装mysql2 gem。我尝试使用32位和64位版本的MySQL服务器,但没有一个让我更进一步。
我安装了Ruby 1.8,开发工具包和Rails平台。我甚至安装了minGW来允许C ++ / C编译。 MySQL Server安装在默认位置。
运行命令时:
C:\Users\Arne>gem install mysql2 -- --with-mysql-include="C:\Program Files (x86)\MySQL\MySQL Server 5.1\include" --with-mysql-lib="C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\"
我从控制台收到以下输出:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
*** 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:/Ruby/bin/ruby
--with-mysql-dir
--without-mysql-dir
--with-mysql-include=${mysql-dir}/include
--with-mysql-lib=${mysql-dir}/lib
--with-libmysqllib
--without-libmysqllib
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x
86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL
\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no
Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2 f
or inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2/ext/mysql2/gem_mak
e.out
根据Rubygems,我的环境输出是:
C:\Users\Arne>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8
- RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby/lib/ruby/gems/1.8
- C:/Users/Arne/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
系统上也安装了以下宝石:
C:\Users\Arne>gem list --local
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (3.0.7)
activemodel (3.0.7)
activerecord (3.0.7)
activeresource (3.0.7)
activesupport (3.0.7)
arel (2.0.9)
builder (3.0.0, 2.1.2)
bundler (1.0.12)
erubis (2.7.0, 2.6.6)
fastthread (1.0.7)
i18n (0.5.0)
mail (2.3.0, 2.2.18)
mime-types (1.16)
mysql (2.8.1 x86-mingw32)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.7.2, 0.6.14)
rack-test (0.5.7)
rails (3.0.7)
railties (3.0.7)
rake (0.8.7)
rdoc (3.5.3, 2.5.11)
rdoc-data (2.5.3)
rubygems-update (1.7.2)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27, 0.3.26)
我不知道缺少什么或错误,但脚本指向的输出文件包含以下数据:
mkmf.log:
have_func: checking for rb_thread_blocking_region()... -------------------- no
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -L. -lmsvcrt-ruby18-static -lshell32 -lws2_32 "
conftest.c: In function 't':
conftest.c:7:53: error: 'rb_thread_blocking_region' undeclared (first use in this function)
conftest.c:7:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4:
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))rb_thread_blocking_region; return 0; }
/* end */
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -L. -lmsvcrt-ruby18-static -lshell32 -lws2_32 "
C:\Users\Arne\AppData\Local\Temp\ccCicaNu.o: In function `t':
C:\Ruby\lib\ruby\gems\1.8\gems\mysql2-0.3.2\ext\mysql2/conftest.c:3: undefined reference to `rb_thread_blocking_region'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { rb_thread_blocking_region(); return 0; }
/* end */
--------------------
have_library: checking for main() in -llibmysql... -------------------- no
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -LC:\Program -L. -lmsvcrt-ruby18-static -llibmysql -lshell32 -lws2_32 "
c:/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 <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4:
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -LC:\Program -L. -lmsvcrt-ruby18-static -llibmysql -lshell32 -lws2_32 "
c:/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: /*top*/
2: int main() { return 0; }
3: int t() { main(); return 0; }
/* end */
--------------------
gem_make.out:
C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no
我希望有人可以指出我做错了什么,或者我的开发系统实际上缺少什么来正确安装和运行这个宝石。
答案 0 :(得分:40)
我终于解决了它:
C:\MySQL
。gem install mysql
gem install mysql2 -- --with-mysql-lib=C:\MySQL\lib --with-mysql-include=C:\MySQL\include
gem install rails
gem install fastthread
gem install haml
现在它正在成为一种魅力。看起来MySQL gem在处理64位时遇到了查找数据的问题。
答案 1 :(得分:19)
这对我有用:Win7 64 / MySQL 5.5 64位/ Ruby 1.9.2:
C:\Ruby192\bin
AND C:\Ruby192\lib
,或者您的lib和bin所在的位置。gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.5"'祝你好运。
答案 2 :(得分:6)
如果仍然出现错误,请在 -
上交叉检查安装步骤http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
按照上述步骤,大多数用户都可以安装mysql2 gem。
答案 3 :(得分:2)
接受的答案对我不起作用,另一个也没有。但是,MG对Ritesh链接的评论为我做了伎俩。我必须指定版本0.2.6,并包含参数--platform = ruby。 (注意:我还必须下载MySQL的“noinstall”版本才能获得/ lib / opt)
以下是我在Windows上安装gem的方法
gem install mysql2 -v 0.2.6 -- --platform=ruby --with-mysql-lib=C:\Ruby192\MySQL\lib\opt --with-mysql-dir=C:\Ruby192\MySQL
答案 4 :(得分:1)
我知道该线程与Windows有关但我在Linux上搜索相同的问题并通过安装lib“libmysqlclient-dev”修复它
答案 5 :(得分:1)
我在64位Windows 7下遇到类似的MySQL 5.6问题。这里给出的主要解决方案有效。 (kobalz建议的只是复制dll的解决方案没有用。不知道为什么它适用于kobalz而不适合我!)
然后我遇到了另一个问题,这个问题在本文中描述:
mysql2 gem compiled for wrong mysql client library
这里描述的解决方案避免了下载完整的32位MySQL并修复了这两个问题。本质上,下载mysql连接器(一个小得多的下载)并使用它来编译mysql2 gem。您必须下载完全正确的版本,如帖子中所述。就我而言:
http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
然后将lib \ libmysql.dll文件从那里复制到您的Ruby bin目录中,如上所述。
我将连接器放入c:\ mysql-connector-c-noinstall-6.0.2-win32
所以构建和安装gem的命令是:
gem install mysql2 - --with-mysql-lib =&#34; c:\ mysql-connector-c-noinstall-6.0.2-win32 \ lib&#34; --with MySQL的-包括=&#34; C:\ MySQL的连接器-C-noinstall-6.0.2-的win32 \包括&#34; --with MySQL的-DIR =&#34; C:\ MySQL的连接器-C-noinstall-6.0.2-win32的&#34;
当我运行rake进行迁移时,我遇到了进一步的问题,但那是因为我一直在使用mysql gem(不是mysql2)而我忘记更新我的database.yml。使用mysql2 gem,需要说:
发展: 适配器:mysql2
而不是
发展: adapter:mysql
这一点很明显,一旦你弄明白了,但我得到的错误信息与之前的错误信息相似,所以看起来好像我的宝石还有问题。
答案 6 :(得分:1)
这个适用于我的MariaDB 5.5安装:
gem install mysql2 - ' - with-mysql-lib =“c:\ Program Files(x86)\ MariaDB 5.5 \ lib”--with-mysql-include =“c:\ Program Files(x86)\ MariaDB 5.5 \ include \ mysql“'
使用以下命令构建本机扩展:' - with-mysql-lib =“c:\ Program Files(x86)\ Maria DB 5.5 \ lib“--with-mysql-include =”c:\ Program Files(x86)\ MariaDB 5.5 \ include \ mys QL“'
如果您打算使用Ruby x64,请务必使用x64 MariaDB软件包。 当然,在我的情况下,不要忘记将C:\ Program Files(x86)\ MariaDB 5.5 \ lib \ libmysql.dll复制到c:\ Ruby200 \ bin。
答案 7 :(得分:0)
将位于MySQL安装的bin目录中的libmysql.dll复制到Ruby安装的bin目录中。我的位于C:\ Program Files \ MySQL和C:\ Ruby。
答案 8 :(得分:0)
这是在Windows 8 64bit和使用ruby 64bit
上对我有用的下载并安装MYSQL Server 5.6 64位
然后运行命令:
gem install mysql2 -v&#39; 0.3.16&#39; - &#39; - with-mysql-lib =&#34; c:\ Program Files \ MySQL \ MySQL Server 5.6 \ lib&#34; --with-mysql-include =&#34; c:\ Program Files \ MySQL \ MySQL Server 5.6 \ include&#34;&#39;
希望这会有所帮助