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

zen*_*ope 64 ruby mysql ruby-on-rails mysql2 ruby-on-rails-4

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

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
Run Code Online (Sandbox Code Playgroud)

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

brew uninstall --force mysql && brew install mysql
Run Code Online (Sandbox Code Playgroud)

然后运行:

sudo gem install mysql2
Run Code Online (Sandbox Code Playgroud)

正如在这里提出的一些类似问题的建议,但它仍然导致与上述相同的错误.

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

Ale*_*rdi 145

对于仍然遇到问题的人:

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

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

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

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
Run Code Online (Sandbox Code Playgroud)

这对我有用.

有关更多信息,请参阅bundler的文档.

  • 如果您只想使用`gem install`,则以下工作:`gem install mysql2 -v'0.3.21' - --with-ldflags = -L/usr/local/opt/openssl/lib --with- CPPFLAGS = -I在/ usr /本地的/ opt/OpenSSL的/ include` (71认同)
  • --with-cppflags在最新的OSX上似乎已中断。我相信可以省略它。`bundle config --local build.mysql2“ --with-ldflags = -L / usr / local / opt / openssl / lib” (3认同)
  • @ the12 niels的解决方案适用于``宝石安装'',我的适用于``捆绑安装''。您到底遇到了什么问题,您可以发布该错误吗?我发布的解决方案仍然适用于我。 (2认同)
  • 捆绑配置命令对我不起作用(尽管过去有用)。niels 的“gem install”命令确实起作用了(几个小时后)。捆绑配置命令失败,因为它看起来像传递了 --with-ldflags 和 --with-cppflags 作为 clang 的参数,产生 clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl /包括' (2认同)

All*_*len 36

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

我最近通过Mac App Store更新了Xcode,每次我这样做,我都发现我必须重新安装命令行工具.

xcode-select --install
Run Code Online (Sandbox Code Playgroud)


ste*_*nis 23

尝试这个:

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

(适当更新版本)

  • 首先安装 `brew install openssl` 然后 `gem install mysql2 -v '0.4.10' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/ local/opt/openssl/include ` 为我工作,谢谢! (2认同)

Ale*_*kin 16

错误日志说:

ld: library not found for -lssl
Run Code Online (Sandbox Code Playgroud)

所以,你需要安装libssl:

brew install openssl
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你.

  • 这些都不适合我:-( (8认同)
  • 那还不够,需要像下面这样导出它:`export LIBRARY_PATH = $ LIBRARY_PATH:/ usr / local / opt / openssl / lib /` (7认同)

Gil*_*Him 15

Based on the solution here

brew install openssl

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Run Code Online (Sandbox Code Playgroud)

solved the problem.

  • 我认为这是2019年的正确答案。 (4认同)

小智 11

在 MacBook Air M1(macOS) 上,它对我有用。

安装zstd

酿造安装zstd

安装mysql2

gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib


zen*_*ope 7

感谢@mudasobwa指出我正确的方向.事实证明错误是由未链接的openssl文件引起的,因此运行:

brew reinstall openssl && brew link openssl --force 
Run Code Online (Sandbox Code Playgroud)

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


Ale*_*zov 7

Homebrew 更新 (openssl@1.1) 后有一个新的库路径,所以可以使用:

bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)
bundle install
Run Code Online (Sandbox Code Playgroud)

它会修复 ld: library not found for -lssl error


Saj*_*ani 5

这最终在 macOS Monterey 12.3 (M1 Pro) 上对我有用:

 gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1
Run Code Online (Sandbox Code Playgroud)

请务必阅读安装说明。对我来说值得注意的几点是:

  • 确保 MySQL 已安装 ( brew install mysql)
  • 确保 XCode 选择工具已安装 ( xcode-select --install)
  • 将选项设置with-mysql-dir为安装 mysql 的位置(使用 进行检查brew info mysql