https://www.rubyguides.com/2019/05/ruby-ffi/ にあるコードを写経しています。
module VLC
extend FFI::Library
ffi_lib 'vlc'
attach_function :version, :libvlc_get_version, [], :string
attach_function :new, :libvlc_new, [:int, :int], :pointer
attach_function :libvlc_media_new_path, [:pointer, :string], :pointer
attach_function :libvlc_media_player_new_from_media, [:pointer], :pointer
attach_function :play, :libvlc_media_player_play, [:pointer], :int
attach_function :stop, :libvlc_media_player_stop, [:pointer], :int
attach_function :pause, :libvlc_media_player_pause, [:pointer], :int
end
vlc = VLC.new(0, 0)
media = VLC.libvlc_media_new_path(vlc, "/home/jesus/Downloads/meditation.mp3") # ここでエラー
=> #<FFI::Function address=0x000000010ac8c770>
irb(main):045:0> puts VLC.get_version
3.0.8 Vetinari
=> nil
irb(main):046:0> vlc = VLC.new(0, 0)
=> #<FFI::Pointer address=0x0000000000000000>
irb(main):047:0> path = '/tmp/ffi/that.mp3'
=> "/tmp/ffi/that.mp3"
irb(main):048:0> media = VLC.libvlc_media_new_path(vlc, path)
(irb):48: [BUG] Segmentation fault at 0x0000000000000018
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
Don't forget to include the above Crash Report log file in bug reports.
-- Control frame information -----------------------------------------------
c:0037 p:---- s:0202 e:000201 CFUNC :libvlc_media_new_path
c:0036 p:0015 s:0196 E:000ad8 EVAL (irb):48 [FINISH]
c:0035 p:---- s:0192 e:000191 CFUNC :eval
c:0034 p:0021 s:0184 e:000183 METHOD /Users/foo/.rbenv/versions/2.6.5/lib/ruby/2.6.0/irb/workspace.rb:85
[...]
bindingライブラリを書くのは初めて何を調べればいいかわかりません。どのようにデバッグすればいいでしょうか?
PATH
で指定されているディレクトリパスに vlc コマンドがない」ことが考えられます。こちらの環境は Ubuntu 20.04.1 ですが、vlc コマンドがインストールされていないと同様のエラー(segmentation fault
)が発生します。が発生し、
VLC.libvlc_get_version` には到達しないでしょう。brew cask install vlc
でインストールしたんですが、もしかしてbindingライブラリを作りために何かが足りない? もしそうなら、どうすれば足りないパッケージをエラーログから探せるんでしょうか、、、。python-vlc
は動いたのでライブラリは足りていそうでした。ffiを使わないで作ってみようと想います。