1

不幸的是,我没有从这个开放的 gl 教程中得到一个简单的示例程序来工作。

ghc --make gfx.hs
Could not find module ‘Graphics.UI.GLUT’
[..]

然后我尝试了以下方法:

cabal install GLUT

Warning: The package list for 'hackage.haskell.org' is 44.1 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Configuring OpenGLRaw-3.2.2.0...
Failed to install OpenGLRaw-3.2.2.0
Build log ( /home/m/.cabal/logs/OpenGLRaw-3.2.2.0.log ):
Configuring OpenGLRaw-3.2.2.0...
setup-Simple-Cabal-1.22.5.0-x86_64-linux-ghc-7.10.3: Missing dependency on a
foreign library:
* Missing C library: GL
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
cabal: Error: some packages failed to install:
GLURaw-2.0.0.2 depends on OpenGLRaw-3.2.2.0 which failed to install.
GLUT-2.7.0.10 depends on OpenGLRaw-3.2.2.0 which failed to install.
OpenGL-3.0.1.0 depends on OpenGLRaw-3.2.2.0 which failed to install.
OpenGLRaw-3.2.2.0 failed during the configure step. The exception was:
ExitFailure 1

看起来缺少的 C 库是问题所在。我正在使用 nixOS,有人知道我必须执行哪些步骤才能使其运行吗?

4

3 回答 3

2

如果你想使用nix-shell

$ nix-shell -p 'haskellPackages.ghcWithPackages (p: [ p.GLUT ])'

会给你一个ghc知道的shellGLUT

我已经尝试使用此代码(来自您提到的 wiki页面)

import Graphics.UI.GLUT

main :: IO ()
main = do
  (_progName, _args) <- getArgsAndInitialize
  _window <- createWindow "Hello World"
  displayCallback $= display
  mainLoop

display :: DisplayCallback
display = do
  clear [ ColorBuffer ]
  flush

但更可取的方法是创建shell.nix,这样您就不需要记住它。要使用shell.nix,只需nix-shell在它所在的目录或nix-shell /path/to/shell.nix任何地方调用不带参数的方法。

shell.nix手册中采用

{ nixpkgs ? import <nixpkgs> {} }:
with nixpkgs;
let
  ghc = haskellPackages.ghcWithPackages (ps: with ps; [
          GLUT
        ]);
in
stdenv.mkDerivation {
  name = "my-haskell-env";
  buildInputs = [ ghc ];
  shellHook = "eval $(egrep ^export ${ghc}/bin/ghc)";
}

对于一个更大的项目,您可能想要使用cabal,或者stack但我认为那将是另一个故事。

于 2017-12-28T08:25:24.693 回答
-1

在 Linux(Nix 是 Linux 发行版)上,LSB 指定它libGL是桌面配置文件的一部分。这意味着至少要安装 X11 客户端库。libGL虽然有点特殊,但允许被图形驱动程序安装覆盖。

这归结为:为您的 GPU 安装图形驱动程序。如果您使用的是 Intel 或 AMD GPU,请安装 Mesa 驱动程序。如果您的系统有 NVidia GPU,我推荐使用专有的 NVidia 驱动程序。

于 2016-10-29T09:29:36.250 回答
-1

在 nixos 中,库通常在cabal预期的路径上不可用。尝试以下操作:

nix-shell -p libGL libGLU freeglut cabal install GLUT

于 2017-12-02T19:44:55.557 回答