0

首先尝试使用berkshelf gem,但它说

bundle exec berks coolbook test_cookbook
    D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/win32/api.rb:20:
    in `require': cannot load such file -- ffi (LoadError)
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/win
    32/api.rb:20:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/win
    32/api/security.rb:19:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/win
    32/api/security.rb:19:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/win
    32/security.rb:19:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/win
    32/security.rb:19:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/fil
    e_access_control/windows.rb:20:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/fil
    e_access_control/windows.rb:20:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/fil
    e_access_control.rb:30:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/fil
    e_access_control.rb:30:in `<class:FileAccessControl>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/fil
    e_access_control.rb:27:in `<class:Chef>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/fil
    e_access_control.rb:22:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/mix
    in/enforce_ownership_and_permissions.rb:19:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/mix
    in/enforce_ownership_and_permissions.rb:19:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/pro
    vider.rb:23:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/pro
    vider.rb:23:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/pla
    tform.rb:26:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/chef-10.16.2/lib/chef/pla
    tform.rb:26:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/berkshelf-1.1.6/lib/berks
    helf.rb:2:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/berkshelf-1.1.6/lib/berks
    helf.rb:2:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/berkshelf-1.1.6/bin/berks
    :3:in `require'
            from D:/dev/vagrant/vagrant/embedded/gems/gems/berkshelf-1.1.6/bin/berks
    :3:in `<top (required)>'
            from D:/dev/vagrant/vagrant/embedded/gems/bin/berks:23:in `load'
            from D:/dev/vagrant/vagrant/embedded/gems/bin/berks:23:in `<main>'

然后尝试使用不同版本重新安装 ffi gem

gem uninstall ffi
gem install ffi -v 1.0.9

gem uninstall ffi
gem install ffi

它安装得很好,但是在安装文档时出现了问题

1 gem installed
Installing ri documentation for ffi-1.3.1-x86-mingw32...
Enclosing class/module 'moduleFFI' for class AbstractMemory not known
Enclosing class/module 'moduleFFI' for class NullPointerError not known
Enclosing class/module "classMemory" for alias put_" #name, "put_" #old); \
    rb_define_alias(classMemory, "get_" #name, "get_" #old); \
    rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \
    rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \
    rb_define_alias(classMemory, "write_" #name, "write_" #old); \
    rb_define_alias(classMemory, "read_" #name, "read_" #old); \
    rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \
    rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \
    rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \

    rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \

    rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old);
 \
    rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old);
 \
    rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old
); \
    rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old);
 \
    rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #o
ld); \
    rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old
);

    ALIAS(char, int8);
    ALIAS(short, int16);
    ALIAS(int, int32);
    ALIAS(long_long, int64);

    /*
     * Document-method: put_float32
     * call-seq: memory.put_float32offset, value)
     * @param [Numeric] offset
     * @param [Numeric] value
     * @return [self]
     * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_f
loat).
     */
    rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
    /*
     * Document-method: get_float32
     * call-seq: memory.get_float32(offset)
     * @param [Numeric] offset
     * @return [Float]
     * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
     */
    rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
    rb_define_alias(classMemory, "put_float put_float32 not known
Enclosing class/module "classMemory" for alias get_float get_float32 not known
Enclosing class/module "classMemory" for alias put_array_of_float put_array_of_f
loat32 not known
Enclosing class/module "classMemory" for alias get_array_of_float get_array_of_f
loat32 not known
Enclosing class/module "classMemory" for alias put_double put_float64 not known
Enclosing class/module "classMemory" for alias get_double get_float64 not known
Enclosing class/module "classMemory" for alias put_array_of_double put_array_of_
float64 not known
Enclosing class/module "classMemory" for alias get_array_of_double get_array_of_
float64 not known
Enclosing class/module "classMemory" for alias size total not known
Enclosing class/module 'moduleFFI' for class ArrayType not known
Enclosing class/module 'moduleFFI' for class Buffer not known
Enclosing class/module "BufferClass" for alias length total not known
Enclosing class/module 'moduleFFI' for module DataConverter not known
Enclosing class/module 'moduleFFI' for class DynamicLibrary not known
Enclosing class/module 'LibraryClass' for class Symbol not known
Enclosing class/module 'rbffi_TypeClass' for class Mapped not known
Enclosing class/module 'rbffi_StructLayoutClass' for class CharArray not known
Enclosing class/module "rbffi_StructLayoutCharArrayClass" for alias to_str to_s
not known
Installing RDoc documentation for ffi-1.3.1-x86-mingw32...
Enclosing class/module 'moduleFFI' for class AbstractMemory not known
Enclosing class/module 'moduleFFI' for class NullPointerError not known
Enclosing class/module "classMemory" for alias put_" #name, "put_" #old); \
    rb_define_alias(classMemory, "get_" #name, "get_" #old); \
    rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \
    rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \
    rb_define_alias(classMemory, "write_" #name, "write_" #old); \
    rb_define_alias(classMemory, "read_" #name, "read_" #old); \
    rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \
    rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \
    rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \

    rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \

    rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old);
 \
    rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old);
 \
    rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old
); \
    rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old);
 \
    rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #o
ld); \
    rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old
);

    ALIAS(char, int8);
    ALIAS(short, int16);
    ALIAS(int, int32);
    ALIAS(long_long, int64);

    /*
     * Document-method: put_float32
     * call-seq: memory.put_float32offset, value)
     * @param [Numeric] offset
     * @param [Numeric] value
     * @return [self]
     * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_f
loat).
     */
    rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
    /*
     * Document-method: get_float32
     * call-seq: memory.get_float32(offset)
     * @param [Numeric] offset
     * @return [Float]
     * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
     */
    rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
    rb_define_alias(classMemory, "put_float put_float32 not known
Enclosing class/module "classMemory" for alias get_float get_float32 not known
Enclosing class/module "classMemory" for alias put_array_of_float put_array_of_f
loat32 not known
Enclosing class/module "classMemory" for alias get_array_of_float get_array_of_f
loat32 not known
Enclosing class/module "classMemory" for alias put_double put_float64 not known
Enclosing class/module "classMemory" for alias get_double get_float64 not known
Enclosing class/module "classMemory" for alias put_array_of_double put_array_of_
float64 not known
Enclosing class/module "classMemory" for alias get_array_of_double get_array_of_
float64 not known
Enclosing class/module "classMemory" for alias size total not known
Enclosing class/module 'moduleFFI' for class ArrayType not known
Enclosing class/module 'moduleFFI' for class Buffer not known
Enclosing class/module "BufferClass" for alias length total not known
Enclosing class/module 'moduleFFI' for module DataConverter not known
Enclosing class/module 'moduleFFI' for class DynamicLibrary not known
Enclosing class/module 'LibraryClass' for class Symbol not known
Enclosing class/module 'rbffi_TypeClass' for class Mapped not known
Enclosing class/module 'rbffi_StructLayoutClass' for class CharArray not known
Enclosing class/module "rbffi_StructLayoutCharArrayClass" for alias to_str to_s
not known


gem uninstall ffi
gem install ffi

但是没有 ffi 安装解决了 berkshelf 的主要问题。

4

2 回答 2

1

我在 64 位 Linux 下安装另一个 gem 时遇到了类似的问题。编译 gem 时,我会得到关于 ffi gem 的完全相同的错误。我的解决方法是安装 libffi-dev 包并且它有效。这个包有一个用于 Windows/MingW 版本的 X86-64,所以我建议确保你已经安装了它。

于 2013-09-11T08:44:48.587 回答
0

对于 ruby​​ 版本 1.9.3 ruby​​ 1.9.3p551 和 64 位 linux,我也有类似的问题。第一步是安装 libffi-dev,如答案 1。

gem uninstall ffi
gem install ffi

仍然有同样的问题。只有在添加了 rdoc gem 的安装之后:

gem install rdoc
gem uninstall ffi
gem install ffi

工作没有错误。

于 2015-05-06T05:42:48.627 回答