yyy

CTFつよくなりたい

rthornton128/goncursesがgo getで入らない時

はじめに

GWも終わりそうですね. 今回, rthornton128/goncurses を使ってみようとしたらgo getで躓いたのでいろいろ書いておきます.環境はUbuntu16.04 LTSです.

rthornton128/goncurses

github.com

ncursesというTUIを作成するための便利ライブラリがありますが,それをGo言語でも使えるようなものです.

で,こちらをインストールしようと go get したのですが

$ go get -u github.com/rthornton128/goncurses
# pkg-config --cflags ncurses form menu ncurses ncurses panel
Package ncurses was not found in the pkg-config search path.
Perhaps you should add the directory containing `ncurses.pc'
to the PKG_CONFIG_PATH environment variable
No package 'ncurses' found
Package form was not found in the pkg-config search path.
Perhaps you should add the directory containing `form.pc'
to the PKG_CONFIG_PATH environment variable
No package 'form' found
Package menu was not found in the pkg-config search path.
Perhaps you should add the directory containing `menu.pc'
to the PKG_CONFIG_PATH environment variable
No package 'menu' found
Package ncurses was not found in the pkg-config search path.
Perhaps you should add the directory containing `ncurses.pc'
to the PKG_CONFIG_PATH environment variable
No package 'ncurses' found
Package ncurses was not found in the pkg-config search path.
Perhaps you should add the directory containing `ncurses.pc'
to the PKG_CONFIG_PATH environment variable
No package 'ncurses' found
Package panel was not found in the pkg-config search path.
Perhaps you should add the directory containing `panel.pc'
to the PKG_CONFIG_PATH environment variable
No package 'panel' found
pkg-config: exit status 1

このようなエラーが出てしまいインストールできませんでした.思い当たる節としては,そもそもncurses入れてなかったので,まずはncursesをインストールしていきます.

yaneno-suzume.at.webry.info

ちょうど,同じ環境で試してる人がいましたがgccのバージョンの問題で最新版が入らないと書いてあります.僕のgccはこの5.31よりは新しい5.4だったので入るかもしれませんでしたが,確実に入りそうなncurses-5.7を入れることにしました.

$ wget http://ftp.gnu.org/gnu/ncurses/ncurses-5.7.tar.gz
$ tar -xvzf ncurses-5.7.tar.gz
$ cd ncurses-5.7
$ ./configure
$ make
$ sudo make install

これでncursesは入りましたが go get で出ていたエラーは全て,pcファイルを PKG_CONFIG_PATH に追加するべきだ,みたいなやつです. PKG_CONFIG_PATH ってなんだと思い調べてみると, /usr/lib/pkgconfig または /usr/local/lib/pkgconfig を通せばいいっぽいです.

askubuntu.com

自分の場合は /usr/lib/pkgconfig があったのでこれを通すようにシェルの設定ファイルに export PKG_CONFIG_PATH=/usr/lib/pkgconfig を追加しました.

そして拡張子がpcのファイルを PKG_CONFIG_PATH に追加する必要がありますが,これらがどこにあるのかわからずググると以下のgistが見つかりました.

gist.github.com

これを参考に,上記でmakeしたディレクトリを /usr/local/opt/ へコピーし,/usr/local/opt/ncurses-5.7 という風にしました.あとは,上記のgistにあるpcファイルの prefix/usr/local/opt/ncurses-5.7 に, Description のバージョンを6.0から5.7にして4つのpcファイルを PKG_CONFIG_PATH に配置してから go get したところ上手く入りました.

libncurses5-dev

ここまでいろいろと書きましたが,これパッケージマネージャーから入らんの?と思い調べてみると, libncurses5-dev というパッケージが見つかったので,これを apt-get install してからパスをいい感じに設定してもよかったかもしれません.

Ubuntu – パッケージのファイル一覧: libncurses5-dev/xenial/amd64

おまけ

OS Xでやっている方もいらっしゃったので,OS Xの人はこちらを参考にするといいと思います.

kandayasu.hatenablog.com