diesel_cli のインストールで失敗する場合の対処法
$ cargo install diesel_cli --no-default-features --features postgres した時に以下のようなエラーが出る場合の対処方法を記す。
$ cargo install diesel_cli --no-default-features --features postgres
...
Compiling diesel_cli v1.4.1
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "-arch" "x86_64" "/var/folders/y_/4r9vf_jn4qx6wd44z61hd7bm0000gp/T/cargo-installc0nGsu/release/deps/diesel-c3215a2deafd6029.diesel.47e90c54-cgu.0.rcgu.o" "/var/folders/y_/4r9vf_jn4qx6wd44z61hd7bm0000gp/T/cargo-installc0nGsu/release/deps/diesel-c…nodefaultlibs"...
= note: ld: library not found for -lpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: failed to compile `diesel_cli v1.4.1`, intermediate artifacts can be found at `/var/folders/y_/4r9vf_jn4qx6wd44z61hd7bm0000gp/T/cargo-installc0nGsu`
Caused by:
could not compile `diesel_cli` due to previous error
結論
以下のどちらかで解決する。
- postgresql をインストールする
- libpq をインストールして PATH 通す
$ brew install postgresql $ cargo install diesel_cli --no-default-features --features postgres # or $ brew install libpq $ PATH="/usr/local/opt/libpq/bin:$PATH" cargo install diesel_cli --no-default-features --features postgres
公式ドキュメント(のドラフト)的には postgresql をインストールするよう書いてあるので、普通にそっちで良さそう。
See. https://github.com/diesel-rs/diesel/blob/v1.4.8/guide_drafts/backend_installation.md#mac-osx
説明
--no-default-features --features postgresは diesel のバックエンド(DB)を postgres に限定するオプション、デフォルトでは diesel は mysql, sqlite, postgres 全てのクライアントライブラリのインストールを要求する- libpq は keg-only(デフォルトで PATH が通らない)なパッケージなので、明示的にパス指定してやらないと動作しない
- 以下、
$ brew install libpqした時に表示されるメッセージlibpq is keg-only, which means it was not symlinked into /usr/local, because conflicts with postgres formula.
- 以下、