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

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

 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 

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

 brew uninstall --force mysql && brew install mysql 

然后运行:

 sudo gem install mysql2 

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

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

错误日志说:

 ld: library not found for -lssl 

所以,你需要安装libssl

 brew install openssl 

希望能帮助到你。

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

当您通过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" 

这对我有用。

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

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

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

 xcode-select --install 

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

 brew reinstall openssl && brew link openssl --force 

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