LoginSignup
3
0

More than 3 years have passed since last update.

rb-inotifyを使う際の注意点

Posted at

▼結論

inotifyはLinux特有のAPIであるため、macOS上ではrb-inotifyは動作せず、Railsを立ち上げようとするとエラーとなる。
エラー解消方法としてはGemfileからrb-inotifyを削除してbundle installを実行する。

ただ、これって回避策であって解決策じゃないんだよなぁ。。。

▼エラーメッセージ

rb-inotifyが入った状態でrailsサーバーを立ち上げると以下のようなエラーメッセージが表示される。

Function 'inotify_init' not found in [libc.dylib] (FFI::NotFoundError)

●FFIって何?

Foreign function interface (FFI)とは、あるプログラミング言語から他のプログラミング言語で定義された関数などを利用するための機構。主に高水準言語からC/C++などの関数やメソッドを呼び出し、OS固有の機能などを利用するために使用されることが多い

Foreign function interface

どうやらRubyがLinuxのAPIであるinotifyを呼び出そうとしており、inorifyがLinux特有のAPIとしてCなどの言語で定義されているため、LinuxであればinorifyのFFIがいるはずだが、macOSにはいないためエラーになっているらしい。

●rb-inotifyって何?

A thorough inotify wrapper for Ruby using FFI.

guard/rb-inotify

Rubyでinotifyを使うためのgemで、FFIを使っていると説明されている。

●inotifyって何?

Linux2.6から追加されたinotifyというAPIは、ファイルやディレクトリーでオープン、クローズ、移動/名前変更、削除、作成、属性の変更などといったファイルシステムイベントを監視することができます。

inotify-toolsでファイルやディレクトリを監視する

3
0
0

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
3
0