LoginSignup
2
2

More than 5 years have passed since last update.

Ubuntu 18.04 において rbczmq のインストールをなんとか進めてみる

Last updated at Posted at 2018-07-12

ConoHaでUbuntu 18.04に乗り換えたのですが、なんぼか更新しているうちにrbczmqのインストールでエラー停止してしまいました。
rbenv,bundlerも使っていますので呪文がしつこいですが(省略はしたくない)あしからず。

Gemfile
gem "rbczmq"
console
rbenv exec bundle install
error_message
zdir.c: In function ‘zdir_new’:
zdir.c:156:9: error: ‘readdir_r’ is deprecated [-Werror=deprecated-declarations]
         int rc = readdir_r (handle, entry, &result);
         ^~~
In file included from ../include/czmq_prelude.h:257:0,
                 from ../include/czmq.h:31,
                 from zdir.c:35:
/usr/include/dirent.h:183:12: note: declared here
 extern int readdir_r (DIR *__restrict __dirp,
            ^~~~~~~~~
zdir.c:159:13: error: ‘readdir_r’ is deprecated [-Werror=deprecated-declarations]
             rc = readdir_r (handle, entry, &result);
             ^~
In file included from ../include/czmq_prelude.h:257:0,
                 from ../include/czmq.h:31,
                 from zdir.c:35:
/usr/include/dirent.h:183:12: note: declared here
 extern int readdir_r (DIR *__restrict __dirp,
            ^~~~~~~~~
cc1: all warnings being treated as errors
Makefile:774: recipe for target 'zdir.lo' failed

readdir_r関数を使ってくれるなというエラーなんですけど、これ数年未改修で放置されててついにコンパイラがエラー扱いし始めたのですね。
で、このエラーの出所なんですが、rbczmqがリンクするczmqライブラリのビルドの中で起こってます。ライブラリのソースが古い、ということでしょうね。なんとかしたってえな作者さん。

手当てその1

まずオリジナルのライブラリのバイナリを参照するようにしてみました。

console
sudo apt install libzmq3-dev libczmq-dev
rbenv exec bundle config build.rbczmq --with-system-libs
rbenv exec bundle install

実行したらエラー

console
ruby: symbol lookup error: /home/anuser/.../rbczmq-1.7.9/lib/rbczmq_ext.so: undefined symbol: zmutex_new

$ sudo apt search czmq
ソート中... 完了
全文検索... 完了
libczmq-dev/bionic,now 4.1.0-2 amd64 [インストール済み]
  High-level C binding for ZeroMQ (development files)

libczmq4/bionic,now 4.1.0-2 amd64 [インストール済み、自動]
  High-level C binding for ZeroMQ

rsyslog-czmq/bionic 8.32.0-1ubuntu4 amd64
  ZeroMQ protocol support for rsyslog via CZMQ

zmutex_newはczmq/3以降ではdeprecatedだという。どこかでczmq/2が必要と読んだ記憶がある。ということはrbczmqのコードが古いということになり、これは詰んでもたんちゃうか。

手当てその2

よそのライブラリを参照するのは止めて、エラー抑止を試します。

あかんケース

console
rbenv exec bundle exec gem uninstall rbczmq
export CFLAGS=-Wno-deprecated
rbenv exec bundle install

。。。だめでした。こんな当てずっぽうでは。extconf.rbを直接変更することになりそう。それには本家からforkして、Gemfileも切替えねば。

手当てその3

インストール時に設定を工夫するのではなくて、コードにエラー抑止の指定を入れ込みます。
ENVを参照して外部から読み込むこともできますが、簡易に簡易に。

forkしてゴニョゴニョしたケース

作者のgitforkしてextconf.rbを修正しました。できれば確認してください。1ヶ所修正を誤爆しました。
あとは下記のようにファイルに修正を加えて端末で実行します。

Gemfile
gem "rbczmq" , github: '59t9/rbczmq', branch: 'master'
console
sudo apt purge libczmq-dev
sudo apt autoremove
rbenv exec bundle config github.https true
rbenv exec bundle install
successful
Fetching https://github.com/59t9/rbczmq.git
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 1.16.2
(...)
Using rbczmq 1.8.1 (was 1.7.9) from https://github.com/59t9/rbczmq.git (at master@ad02854)
(...)
Bundle complete!

これでどやろか。

参考

http://zeromq.org/distro:debian
rbczmq の幾つかのインストール方法
https://github.com/SciRuby/iruby/issues/70
Ruby リファレンスマニュアル library mkmf

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2