MySQL 尝试使用 mysql2 gem 安装应用程序时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30834421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:05:53  来源:igfitidea点击:

Error when trying to install app with mysql2 gem

mysqlruby-on-railsrubyruby-on-rails-4mysql2

提问by zenvelope

Im trying to install an open source rails 3.2.21 application that uses the mysql2gem, but when i try and run the bundlecommant I get the following error:

我试图安装一个使用mysql2gem 的开源 rails 3.2.21 应用程序,但是当我尝试运行bundle命令时,我收到以下错误:

Fetching: mysql2-0.3.18.gem (100%)
Building native extensions.  This could take a while...
p
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    /Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.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()... yes
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/5.6.25/lib
-----
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/travis/.sm/pkg/active/lib'
ld: library not found for -lssl
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/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86

I tried uninstalling every version of mysqlI installed via homebrew and reinstalling them, like so:

我尝试卸载mysql通过自制软件安装的每个版本并重新安装它们,如下所示:

brew uninstall --force mysql && brew install mysql

Then running:

然后运行:

sudo gem install mysql2

As suggested by a number of similar questions asked on here, but it still results in the same error as above.

正如此处提出的许多类似问题所建议的那样,但它仍然导致与上述相同的错误。

Please could someone offer guidance on how to get this up and running?

请有人提供有关如何启动和运行的指导吗?

采纳答案by Aleksei Matiushkin

The error log says:

错误日志说:

ld: library not found for -lssl

So, you need to install libssl:

所以,你需要安装libssl

brew install openssl


As it was pointed out in comments, there might be a need to export the path to the library.

正如评论中指出的那样,可能需要将路径导出到库。

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

回答by Alessandro Berardi

For anybody still experiencing the issue:

对于仍然遇到问题的任何人:

When you install openssl via brew, you should get the following message:

当您通过 brew 安装 openssl 时,您应该收到以下消息:

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

Apple 已弃用 OpenSSL,转而使用自己的 TLS 和加密库

一般来说,这不会对您造成任何后果。如果您构建自己的软件并且需要此公式,则需要添加到构建变量中:

LDFLAGS:-L/usr/local/opt/openssl/lib
CPPFLAGS:-I/usr/local/opt/openssl/include
PKG_CONFIG_PATH:/usr/local/opt/openssl/lib/pkgconfig

You can set these build flags (for the local application) by running the following:

您可以通过运行以下命令来设置这些构建标志(对于本地应用程序):

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

This worked for me.

这对我有用。

See bundler's documentationfor more information.

有关更多信息,请参阅捆绑程序的文档

回答by Allen

The solution for me was to install the Xcode Command Line Tools.

我的解决方案是安装 Xcode 命令行工具。

I had recently updated Xcode through the Mac App Store, and every time I do that, I've found that I have to reinstall the Command Line Tools again.

我最近通过 Mac App Store 更新了 Xcode,每次更新时,我发现我必须再次重新安装命令行工具。

xcode-select --install

回答by stereodenis

Try this:

尝试这个:

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

(Update version as appropriate)

(视情况更新版本)

回答by Gilg Him

Based on the solution here

基于这里的解决方案

brew install openssl

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

solved the problem.

解决了这个问题。

回答by zenvelope

Thanks @mudasobwa for pointing me in the right direction. It turns out the error was caused by an unlinked openssl file, so running:

感谢@mudasobwa 为我指明了正确的方向。原来错误是由未链接的 openssl 文件引起的,因此运行:

brew reinstall openssl && brew link openssl --force 

Solved the problem. I found the solution here: OpenSSL, RVM, Brew, conflicting error

解决了问题。我在这里找到了解决方案:OpenSSL、RVM、Brew、冲突错误

回答by Haseeb Zulfiqar

The combination of commands solved it me. I am on Mojave.

命令的组合解决了我。我在莫哈韦沙漠。

brew reinstall openssl && brew link openssl --force

brew reinstall openssl && brew link openssl --force

and then

进而

gem install mysql2 -v '0.4.10' -- \
  --with-ldflags=-L/usr/local/opt/openssl/lib \
  --with-cppflags=-I/usr/local/opt/openssl/include

回答by k1r8r0wn

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

From here: https://gorails.com/setup/osx/10.14-mojave

从这里:https: //gorails.com/setup/osx/10.14-mojave

回答by Emad Saeed

Seems that you miss the main files needed to build mysql2gem

似乎您错过了构建mysql2gem所需的主要文件

sudo apt-get install libsqlite3-dev libmysqlclient-dev -y

libsqlite3-devis not mandatory but install it since it's the default rails DB.

libsqlite3-dev不是强制性的,但安装它,因为它是默认的 rails DB。

回答by Brian J. Fox

I found that I had to use --with-opt-dir=/usr/local/opt.

我发现我必须使用--with-opt-dir=/usr/local/opt.

Specifically, I added the following to my ~/.bundle/configfile:

具体来说,我在我的~/.bundle/config文件中添加了以下内容:

BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt"