Ld Library Not Found For Lssl Mac Mysql

Posted on  by 

背景

  1. Make sure openssl is installed on Mac via Homebrew. Brew install openssl Install mysql2 gem. This helped me when the gem install kept on errorring out about not being able to find the mysql client. I modified @AnshulRiyal's command a little: On Mojave, High Sierra, or Catalina, using homebrew. Fixed my ld: library not found for -lssl.
  2. Mac 上首先要要安装 brew install mysql-connector-c. 修改 mysqlconfig 文件. Ld: library not found for -lssl.

Ld: library not found for -lXXXXX 的解决方法 团队开发的时候每次更新后都有可能碰到各种各样的问题,昨天同事对项目结构做了些修改,更新后编译就遇到下面的情况: ld: library not found for -lAFNetworking 这个错误是说编译时找不到AFNetworking这个链接库,但是我在项目. The problem is that a library is missing. As you can see on this line. Ld: library not found for -lssl This is how we solved it. Step 1: Double-check if openssl is installed and install it if not. Brew install openssl. Step 2: Check if you use bash/zsh/fish or whatever and identify the config file. He is using zsh on mac so the file is /.zshrc. On macOS 10.14 (Mojave) If you get an error like: ld: library not found for -lssl (this usually means you need to install the development package for libssl) you may need to install OpenSSL and link pkg-config to OpenSSL: brew install openssl export PKGCONFIGPATH=$PKGCONFIGPATH:/usr/local/opt/openssl/lib/pkgconfig.

とある教材を見ながらプロジェクトを作成していたところ、bundle install を実行したらエラーが発生したのでメモ。

「Mysqlの導入で発生したエラー解消」という内容で、最終的に「bundleのオプション指定」することにより解消できた。

実行したコマンド

エラー内容

Ld Library Not Found For Lssl Mac Mysql

Ld Library Not Found For Lssl Mac Mysql Download

考えたこと

  • そういえばプロジェクト作成のときにDBをmysqlで指定したのは始めてだな。
  • mysql2 0.5.2 をインストールできないということかな。
  • gem install mysql2 -v '0.5.2'を実行しなさいと言ってるのかしら?
  • Gemfile でmysql2 のバージョンは何になってる?
  • ひとまずググるか。

やったこと

Gemfile の確認

Gemfile 内の記述は以下の通り。

ダメな部分があるか否かが不明のため、ひとまず確認のみ。

エラーログに記載されているコマンドを実行

Ld Library Not Found For Lssl

結果、エラーの解消にはつながらなかった。

ググる!→このコマンドでエラー解消!【解決】

エラーの原因特定、解消方法を調べてみたところ、下記コマンド実行にて解決した。

※追記:解消方法コマンド1行目に$ bundle config --local build.mysql2 '--with-cppflags=-I/usr/local/opt/openssl/include'という記述をしておりましたが、後で実行されるコマンドで上書きされるため不要ということがわかり削除しました。(@keik 様、ご指摘いただきありがとうございます)

その後、下記コマンドを実行することで「You’re on Rails」画面を開くことができたので今回のエラーは解決とする。

Ld Library Not Found For Lssl Mac Mysql Command

原因・学び

今回のエラー解消に際し、色々と調べる中で学んだことをメモ。

エラーについて

どうやら、今回は下記エラーログがポイントだった模様。

原因を言語化すると、opensslのパスがビルドの時に必要(ビルドのときにLDFLAGSとかCPPFLAGSとかにパスを追加する記述が必要)ということ。

ld とは?

ldはGNUリンカーと呼ばれるコマンドとのこと。$ man ld で内容を確認できる。

-lssl は、mysql2 gemインストール時にldコマンドに与えられたオプションの一つらしい。

ここでは詳細の掘り下げはせずに置いておく。。

解決策について

bundle config とは?

下記ページにて詳細を確認する事ができた。

コマンドbundle configにより、Bundlerの設定システムを操作することができるとのこと。

Ld Library Not Found For Lssl Mac Mysql Tutorial

なお、 Bundlerは自身の設定を下記の優先順位で取得する。

 1. ローカルのアプリケーション(app/.bundle/config)
 2. 環境変数
 3. ユーザーのホームディレクトリ(~/.bundle/config)

Ld Library Not Found For Lssl Mac Mysql Database

Ld Library Not Found For Lssl Mac Mysql

また、--localオプションをつけることで、ローカルのアプリケーションに対して設定が可能。つまりプロジェクト単位の設定となる。

宿題

Mac Library Not Found For Lssl

  • bundle config で指定する「LDFLAGS」「CPPFLAGS」についてもう少し調べるべし。
  • ld コマンドについてももう少し。(仮)
aneuryzma wrote:
Hi,
I'm trying to compile some sources and I get the following error message:
/bin/sh ../libtool --mode=link g++ -g -O2 -o pursuit_monitor Monitor.o MonitorParameters.o RGBcolor.o ../../pursuitbase/pursuitbase/libConnection.la ../../pursuitbase/pursuitbase/libGenericValues.la -lpthread -lnsl -lglut -lXi -lGLU -lGL
g++ -g -O2 -o pursuit_monitor Monitor.o MonitorParameters.o RGBcolor.o -Wl,-bind atload ../../pursuitbase/pursuitbase/.libs/libConnection.a ../../pursuitbase/pursuitbase/.libs/libGenericValues.a -lpthread -lnsl -lglut -lXi -lGLU -lGL
ld: library not found for -lnsl
collect2: ld returned 1 exit status
make[3]: * [pursuit_monitor] Error 1
make[2]: * [all-recursive] Error 1
make[1]: * [all] Error 2
make: * [all-recursive] Error 1
What's lnsl library ?
Is something I can remove from makefile configuration ?

The parameter '-lnsl' is a a lower-case 'L' (which describes a library to be searched) followed by the suffix of the name of the library, 'nsl'. The effect is to tell 'ld' to look for a library named 'libnsl.a' or 'libnsl.dylib'. The 'ld' command normally searches for ibraries in the directories /usr/lib and /usr/local/lib . If the 'libnsl' library is in neither of these, addition search directories can be added with the '-L' parameter.
You might try that command with the '-lnsl' parameter removed. If nothing else, it would give you a clue as to what routines were needed from the 'nsl' library, which could help you resolve the problem.

Sep 7, 2009 2:02 PM

Coments are closed