【问题标题】:Errors when using require gosu MAC OS使用 require gosu MAC OS 时的错误
【发布时间】:2016-02-27 18:26:19
【问题描述】:

我正在尝试运行此脚本并且我正在使用 Coderunner 2

require 'rubygems'
require 'gosu'
 class Ball 
   def initialize(the_window)
   @x = 200
   @y = 200
   @w = 20
   @h = 20
   @image = Gosu::Image.new(the_window, "ball.png", false)
end

def draw
    @image.draw(@x, @y , 1)
end
end
class GameWindow < Gosu::Window
    def initialize
    super 800,600, false
    self.caption = "Paddle Game"
    @ball = Ball.new(self)
    end
    def update

    end
    def draw
    @ball.draw
    end
end
window = GameWindow.new
window.show

**

它会返回一条错误消息:

/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require':
    cannot load such file -- gosu (LoadError)
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in 
   `require'
    from paddle_game.rb:2:in `<main>'

我已经安装了 Ruby 2.0.0 和 gems...当我尝试安装 gosu 这是我得到的错误:

Mac-Users-iMac-763:~ macuser$ sudo gem install gosu
Building native extensions.  This could take a while...
ERROR:  Error installing gosu:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4/ext/gosu
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r                     .    /siteconf20151124-93492-9a029w.rb extconf.rb
 The Gosu gem requires some libraries to be installed system-wide.
 See the following site for a list:
 https://github.com/jlnr/gosu/wiki/Getting-Started-on-OS-X

creating Makefile

current directory: /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4/ext/gosu
make "DESTDIR=" clean

current directory: /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4/ext/gosu
make "DESTDIR="
compiling stb_vorbis.c
compiling gosu_wrap.cxx
compiling Audio-Audio.cpp
compiling Bitmap-Bitmap.cpp
compiling Bitmap-BitmapIO.cpp
compiling DirectoriesUnix.cpp
compiling FileUnix.cpp
compiling Graphics-BlockAllocator.cpp
compiling Graphics-Color.cpp
compiling Graphics-Graphics.cpp
compiling Graphics-Image.cpp
compiling Graphics-LargeImageData.cpp
compiling Graphics-Macro.cpp
compiling Graphics-Resolution.cpp
compiling Graphics-ResolutionApple.cpp
compiling Graphics-TexChunk.cpp
compiling Graphics-Texture.cpp
compiling Graphics-Transform.cpp
compiling Input-Input.cpp
compiling Input-TextInput.cpp
compiling Inspection.cpp
compiling IO.cpp
compiling Math.cpp
compiling Text-Font.cpp
compiling Text-Text.cpp
compiling Text-TextApple.cpp
compiling TimingApple.cpp
compiling Utility.cpp
compiling UtilityApple.cpp
compiling Window.cpp
linking shared-object gosu.bundle
clang: error: unknown argument: '-multiply_definedsuppress'
make: *** [gosu.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4 
   for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin- 
  13/2.0.0/gosu-0.10.4/gem_make.out

我已尝试研究并提出不同的建议,但目前无法进一步了解。只是想知道我可能做错了什么,或者我是否应该使用其他编辑器?不知道为什么“要求”对我不起作用。谢谢

【问题讨论】:

    标签: ruby-on-rails macos terminal rubygems


    【解决方案1】:

    我注意到的几件事:

    1. 您的class Ball 缩进了一个空格。
    2. 你需要end你的class Ball方法。
    3. def draw 函数之后,您有一个额外的end
    4. 您的方法需要缩进。
    5. 您的缩进不一致(选择 2 或 4 个空格并遵守约定)
    6. 看到这个帖子回复:require 'rubygems'

    这个版本的代码在我的系统上启动一个窗口(Ubuntu 14 和 Ruby 2.3 并使用我下载的 rvm 1.11.3.9 和 bundledgosu 0.10.8):

    # require 'rubygems'
    require 'gosu'
    
    # class Ball 
    #   def initialize(the_window)
    #     @x = 200
    #     @y = 200
    #     @w = 20
    #     @h = 20
    #     @image = Gosu::Image.new(the_window, "ball.png", false)
    #   end
    # end
    # 
    # def draw
    #   @image.draw(@x, @y , 1)
    # end
    
    # end
    
    class GameWindow < Gosu::Window
      def initialize
        super 800, 600, false          # <-- width, height, fullscreen=false
        self.caption = "Paddle Game"
    #     @ball = Ball.new(self)
      end
    
      def update
      end
    
      def draw
    #     @ball.draw
      end
    end
    
    window = GameWindow.new
    window.show
    

    如果你在 OSX 上使用 Ruby Gosu,你可能想去这里:

    https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X

    不管怎样,我在安装后得到了相同的“LoadError”,并在项目目录中使用“bundler”处理了 gem 依赖项。我访问了GOSU网站的Linux版本:

    https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux

    在命令行中输入后:

    user@ubuntu:~/Ruby/gosu_project$ sudo apt-get install build-essential libsdl2-dev libsdl2-ttf-dev libpango1.0-dev libgl1-mesa-dev libfreeimage-dev libopenal-dev libsndfile-dev
    

    user@ubuntu:~/Ruby/gosu_project$ gem install gosu
    

    我还必须调用:

    user@ubuntu:~/Ruby/gosu_project$捆绑

    http://bundler.io/ - 也适用于 MacOSX...

    每个人:https://github.com/gosu/gosu/wiki/ruby-tutorial

    这个gosu文件:

    # basic Gosu: gui test file
    
    require 'gosu'
    
    class TestWindow < Gosu::Window   # <-- inherits from Gosu Window Super class
    
      def initialize
        super 640, 480, false         # <-- width, height, fullscreen = false
        self.caption = "successful gosu test window"
      end
    
      def update
      end
    
      def draw
      end
    
    end
    
    
    TestWindow.new.show
    

    ...加载一个 640x480 的窗口

    user@ubuntu:~/Ruby/gosu_project$ ruby gosu_test.rb
    

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 2012-12-15
      • 2014-10-17
      • 2014-05-06
      • 2013-08-12
      • 1970-01-01
      相关资源
      最近更新 更多