无法安装旧的mysql2 gem

Ale*_*den 8 ruby rubygems ruby-on-rails mysql2

我正在使用Mac High Sierra.我正在使用带有RVM的Ruby 2.2.1.我需要在这个Ruby on Rails应用程序中使用mysql2.我确实安装了mysql 5.7.我确实安装了xcode和命令行工具.

我只是想让这个公司应用程序在我的本地机器上工作.我知道我非常接近但是当我进行捆绑安装时我有一个最后的错误当我到达mysql2 gem时收到以下错误:

Fetching mysql2 0.3.18
Installing mysql2 0.3.18 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/ext/mysql2
/Users/ahayden/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20180710-52515-2hjll8.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql-connector-c/6.1.11/lib
-----
creating Makefile

current directory: /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18/ext/mysql2
make "DESTDIR="
compiling infile.c
compiling client.c
client.c:359:33: warning: implicit conversion loses integer precision: 'long' to 'unsigned int' [-Wshorten-64-to-32]
        elapsed_time = end_time - start_time;
                     ~ ~~~~~~~~~^~~~~~~~~~~~
client.c:1163:56: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
  mysql2rb = mysql2_mysql_enc_name_to_rb(charset_name, charset_name_len);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~               ^~~~~~~~~~~~~~~~
2 warnings generated.
compiling mysql2_ext.c
compiling result.c
result.c:186:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (i = 0; i < (len - 1); i++) {
              ~ ^  ~~~~~~~
1 warning generated.
linking shared-object mysql2/mysql2.bundle
ld: library not found for -l-lpthread
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/ahayden/.rvm/gems/ruby-2.2.1/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/ahayden/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-17/2.2.0/mysql2-0.3.18/gem_make.out

An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling.

In Gemfile:
  mysql2
Run Code Online (Sandbox Code Playgroud)

我试过安装没有特定的宝石版本的mysql2它可以工作,但它没有解决我的问题.它似乎归结为追溯的底部,它无法找到库-l-lpthread.请帮帮忙,我一整天都在尝试这样做.

Kor*_*yem 43

这为我修好了

gem install mysql2 -v '0.3.21' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
Run Code Online (Sandbox Code Playgroud)

安装openssl后

brew install openssl
Run Code Online (Sandbox Code Playgroud)

  • 另一个可以尝试的方法:`gem install mysql2---with-opt-dir =“ $(brew --prefix openssl)”对我有用,当编译器错误是ld:-lssl找不到库时 (5认同)
  • 这适用于OSX 10.14.2,通过brew安装MySQL 8.0.13.在找到此命令之前浪费了3个小时.谢谢! (3认同)
  • @bxiong同样在这里!我浪费了无数个小时穿越互联网的角落寻求解决方案.我告诉自己我必须回到SO分享这个以节省其他人的时间.很高兴它有所帮助.快乐编码:) (3认同)

Roh*_*han 6

根据共享的描述,似乎mysql依赖项无法安装.

首先,我们需要'找到mysql_config',然后将以下命令中的路径替换为该文件所在的位置.

gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Run Code Online (Sandbox Code Playgroud)

  • 宝石是“ mysql”还是“ mysql2”? (2认同)