-2

我正在尝试运行此示例: https ://raw.githubusercontent.com/elisehuard/game-in-haskell/master/src/Shapes.hs

但我收到错误“freeglut 错误:在没有先调用 'glutInit' 的情况下调用函数。”

我设法将问题隔离到第 39 行:“颜色(亮洋红色)$ translate 0 (-100) $ scale 0.2 0.2 $ text "Boo!""

当我将其更改为:“颜色(亮洋红色)$ translate 0 (-100) $ scale 0.2 0.2 $ blank

它工作正常。

我正在开发 linux mint 19;光泽版 1.13.0.1;光泽渲染 1.13.0.2。


在克隆光泽、构建并将新克隆的库添加到我的堆栈之后

malki@Hood:~/Projects/TstP$ stack build
TstP-0.1.0.0: build (lib + exe)
gloss-1.13.0.1: build (lib)
Completed 2 action(s).
Log files have been written to: /home/malki/Projects/TstP/.stack-work/logs/

--  While building package TstP-0.1.0.0 using:
      /home/malki/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 build lib:TstP exe:TstP-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/malki/Projects/TstP/.stack-work/logs/TstP-0.1.0.0.log

    Preprocessing library for TstP-0.1.0.0..
    Building library for TstP-0.1.0.0..
    Preprocessing executable 'TstP-exe' for TstP-0.1.0.0..
    Building executable 'TstP-exe' for TstP-0.1.0.0..
    [1 of 2] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/TstP-exe/TstP-exe-tmp/Main.o )
    
    /home/malki/Projects/TstP/app/Main.hs:5:1: error:
        Could not find module ‘Graphics.UI.GLFW’
        It is not a module in the current program, or in any known package.
      |
    5 | import "GLFW-b" Graphics.UI.GLFW as GLFW
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:6:1: error:
        Could not find module ‘Graphics.Gloss’
        Use -v to see a list of the files searched for.
      |
    6 | import Graphics.Gloss
      | ^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:7:1: error:
        Could not find module ‘Graphics.Gloss.Rendering’
        Use -v to see a list of the files searched for.
      |
    7 | import Graphics.Gloss.Rendering
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:8:1: error:
        Could not find module ‘Graphics.Gloss.Data.Color’
        Use -v to see a list of the files searched for.
      |
    8 | import Graphics.Gloss.Data.Color
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:9:1: error:
        Could not find module ‘Graphics.Gloss.Data.Picture’
        Use -v to see a list of the files searched for.
      |
    9 | import Graphics.Gloss.Data.Picture
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


--  While building package gloss-1.13.0.1 using:
      /home/malki/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 build lib:gloss --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/malki/Projects/TstP/.stack-work/logs/gloss-1.13.0.1.log

    Preprocessing library for gloss-1.13.0.1..
    Building library for gloss-1.13.0.1..
    [ 1 of 44] Compiling Graphics.Gloss.Data.Bitmap ( Graphics/Gloss/Data/Bitmap.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Graphics/Gloss/Data/Bitmap.o ) [Graphics.Gloss.Rendering changed]
    
    /home/malki/Projects/TstP/gloss/gloss/Graphics/Gloss/Data/Bitmap.hs:15:1: error:
        Could not find module ‘Graphics.Gloss.Rendering’
        There are files missing in the ‘gloss-rendering-1.13.0.2’ package,
        try running 'ghc-pkg check'.
        Use -v to see a list of the files searched for.
       |
    15 | import Graphics.Gloss.Rendering
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
malki@Hood:~/Projects/TstP$ 

这些模块作为全局模块存在(在这个堆栈目录之外编译的东西)。但是它们不存在于光泽克隆中。

malki@Hood:~/Projects/TstP/gloss/gloss$ find ./Graphics
./Graphics
./Graphics/Gloss
./Graphics/Gloss/Geometry
./Graphics/Gloss/Geometry/Angle.hs
./Graphics/Gloss/Geometry/Line.hs
./Graphics/Gloss/Geometry.hs
./Graphics/Gloss/Interface
./Graphics/Gloss/Interface/Pure
./Graphics/Gloss/Interface/Pure/Simulate.hs
./Graphics/Gloss/Interface/Pure/Animate.hs
./Graphics/Gloss/Interface/Pure/Game.hs
./Graphics/Gloss/Interface/Pure/Display.hs
./Graphics/Gloss/Interface/IO
./Graphics/Gloss/Interface/IO/Simulate.hs
./Graphics/Gloss/Interface/IO/Animate.hs
./Graphics/Gloss/Interface/IO/Interact.hs
./Graphics/Gloss/Interface/IO/Game.hs
./Graphics/Gloss/Interface/IO/Display.hs
./Graphics/Gloss/Interface/Environment.hs
./Graphics/Gloss/Data
./Graphics/Gloss/Data/Vector.hs
./Graphics/Gloss/Data/Point.hs
./Graphics/Gloss/Data/ViewState.hs
./Graphics/Gloss/Data/ViewPort.hs
./Graphics/Gloss/Data/Color.hs
./Graphics/Gloss/Data/Point
./Graphics/Gloss/Data/Point/Arithmetic.hs
./Graphics/Gloss/Data/Bitmap.hs
./Graphics/Gloss/Data/Controller.hs
./Graphics/Gloss/Data/Picture.hs
./Graphics/Gloss/Data/Display.hs
./Graphics/Gloss/Internals
./Graphics/Gloss/Internals/Color.hs
./Graphics/Gloss/Internals/Interface
./Graphics/Gloss/Internals/Interface/Common
./Graphics/Gloss/Internals/Interface/Common/Exit.hs
./Graphics/Gloss/Internals/Interface/Event.hs
./Graphics/Gloss/Internals/Interface/ViewState
./Graphics/Gloss/Internals/Interface/ViewState/KeyMouse.hs
./Graphics/Gloss/Internals/Interface/ViewState/Motion.hs
./Graphics/Gloss/Internals/Interface/ViewState/Reshape.hs
./Graphics/Gloss/Internals/Interface/Simulate
./Graphics/Gloss/Internals/Interface/Simulate/Idle.hs
./Graphics/Gloss/Internals/Interface/Simulate/State.hs
./Graphics/Gloss/Internals/Interface/Simulate.hs
./Graphics/Gloss/Internals/Interface/Backend
./Graphics/Gloss/Internals/Interface/Backend/GLFW.hs
./Graphics/Gloss/Internals/Interface/Backend/GLUT.hs
./Graphics/Gloss/Internals/Interface/Backend/Types.hs
./Graphics/Gloss/Internals/Interface/Backend.hs
./Graphics/Gloss/Internals/Interface/Animate.hs
./Graphics/Gloss/Internals/Interface/Callback.hs
./Graphics/Gloss/Internals/Interface/Interact.hs
./Graphics/Gloss/Internals/Interface/Animate
./Graphics/Gloss/Internals/Interface/Animate/Timing.hs
./Graphics/Gloss/Internals/Interface/Animate/State.hs
./Graphics/Gloss/Internals/Interface/Debug.hs
./Graphics/Gloss/Internals/Interface/Game.hs
./Graphics/Gloss/Internals/Interface/Window.hs
./Graphics/Gloss/Internals/Interface/Display.hs
./Graphics/Gloss.hs
malki@Hood:~/Projects/TstP/gloss/gloss$ 

本地图形分支不应该遮蔽现有分支吗?似乎它试图完全取代它。


请指教!

干杯!

4

1 回答 1

2

Gloss 被编译为使用GLFWGLUT 运行 - 请参阅Backend.hs

#ifdef WITHGLUT
defaultBackendState :: GLUTState
#elif  WITHGLFW
defaultBackendState :: GLFWState
#else
#error No default backend defined
#endif

WITHGLUT并且WITHGLFW是构建包时指定的编译时标志。您尝试手动运行的代码设置了一个 GLFW 窗口,然后使用光泽度来渲染事物:看起来您正在使用的光泽度被编译为使用 GLUT 而不是 GLFW,因此手动完成的设置不是充足的。


您需要重新编译光泽以使用 GLFW:

git clone https://github.com/benl23x5/gloss
cd gloss
stack build --flag gloss:glfw --flag gloss:-glut

您可能需要调整构建文件以修复构建期间的错误:堆栈非常擅长解释您需要修复的内容。我不得不:

  • 添加GLFW-b-1.4.8.4@sha256:2d10594c5cfa9d5178596eb6a18106a1318409e47a4108bfe91b89d80684638eextra-deps_stack.yaml
  • 添加Graphics.Gloss.Internals.Interface.Backend.GLUT到. Other-modules_gloss.cabal

然后,您可以修改您尝试运行的示例的构建文件,以stack使用您的本地版本的包,如此处所述

于 2018-12-08T11:56:50.900 回答