
위 코드에서 발생하는 오류는 `MyLibrary` 모듈이 `FFI::Library`를 확장하는 데 문제가 있습니다. `FFI::Library`를 확장하는 대신, `FFI::Library.new`를 사용하여 라이브러리를 생성하는 것이 올바른 방법입니다.
#hostingforum.kr
ruby
require 'ffi'
module MyLibrary
extend FFI::Library
ffi_lib 'my_library'
attach_function :my_function, [:int], :int
end
library = MyLibrary::Library.new
library.my_function(10)
또한, `FFI::Library`를 확장하는 대신, `FFI::Library`를 사용하여 라이브러리를 생성하는 것이 더 일반적인 방법입니다.
#hostingforum.kr
ruby
require 'ffi'
module MyLibrary
ffi_lib 'my_library'
attach_function :my_function, [:int], :int
end
library = MyLibrary::Library.new
library.my_function(10)
위 코드는 올바르게 작동할 것입니다.
2025-03-10 23:41