[英]Error when trying to install app with mysql2 gem
我正在尝试安装一个使用mysql2
gem 的开源 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
我尝试卸载通过自制软件安装的mysql
的每个版本并重新安装它们,如下所示:
brew uninstall --force mysql && brew install mysql
然后运行:
sudo gem install mysql2
正如此处提出的许多类似问题所建议的那样,但它仍然会导致与上述相同的错误。
请有人提供有关如何启动和运行它的指导吗?
对于仍然遇到问题的任何人:
当您通过 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"
这对我有用。
有关更多信息,请参阅捆绑程序的文档。
错误日志说:
ld: library not found for -lssl
所以,你需要安装libssl
:
brew install openssl
正如评论中指出的那样,可能需要将路径导出到库。
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
试试这个:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
(视情况更新版本)
我的解决方案是安装 Xcode 命令行工具。
我最近通过 Mac App Store 更新了 Xcode,每次更新时,我发现我必须再次重新安装命令行工具。
xcode-select --install
基于这里的解决方案
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
解决了这个问题。
感谢@mudasobwa 为我指明了正确的方向。 原来错误是由未链接的 openssl 文件引起的,因此运行:
brew reinstall openssl && brew link openssl --force
解决了问题。 我在这里找到了解决方案: OpenSSL、RVM、Brew、冲突错误
Homebrew 更新 (openssl@1.1) 后有一个新的库路径,所以可以使用:
bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)
bundle install
它将修复ld: library not found for -lssl error
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
命令的组合解决了我。 我在莫哈韦沙漠。
brew reinstall openssl && brew link openssl --force
接着
gem install mysql2 -v '0.4.10' -- \
--with-ldflags=-L/usr/local/opt/openssl/lib \
--with-cppflags=-I/usr/local/opt/openssl/include
似乎您错过了构建mysql2
gem 所需的主要文件
sudo apt-get install libsqlite3-dev libmysqlclient-dev -y
libsqlite3-dev
不是强制性的,但安装它,因为它是默认的 rails DB。
Mac Catalina 使用 Homebrew 修复: gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
以下命令适用于我的 Mac os 12.1 MacOs Monterey
gem install mysql2 -v '0.5.3' -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include
请参考此链接了解更多详情https://github.com/brianmario/mysql2/issues/1175
这最终在 macOS Monterey 12.3 (M1 Pro) 上对我有用:
gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1
请务必阅读安装说明。 对我来说值得注意的是:
brew install mysql
)xcode-select --install
)with-mysql-dir
选项设置为安装 mysql 的任何位置(检查brew info mysql
)在 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
我在 Monterey M1 Mac 上的步骤
brew install openssl@3
brew install zstd
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
bundle config --local build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib"
bundle install
多年来,我一直在使用 mysql2 gem 进行编码,并且时常遇到这个问题。
今天我发现这个神奇的选项-- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
不再适用于我的苹果。 事实上,看起来 brew 安装 openssl 的默认位置已经改变:
$ brew reinstall openssl
...
If you need to have openssl@3 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@3 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
因此,根据消息,我不得不对命令进行一些更改并最终使其生效:
$ gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/opt/homebrew/opt/openssl@3/lib --with-cppflags=-I/opt/homebrew/opt/openssl@3/include
希望这会帮助别人!
这对我在 MacOs 12.6 (Monterey) 上有帮助
brew install mysql openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
gem install mysql2 -v '0.5.3' \
--source 'https://rubygems.org/' -- \
--with-cppflags=-I/usr/local/opt/openssl/include \
--with-ldflags=-L/usr/local/opt/openssl/lib
bundle install
感谢https://github.com/brianmario/mysql2/issues/1175#issuecomment-1069721834
我发现我必须使用--with-opt-dir=/usr/local/opt
。
具体来说,我在~/.bundle/config
文件中添加了以下内容:
BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.