【问题标题】:nixos + haskell + opengl (prerequisites)nixos + haskell + opengl(先决条件)
【发布时间】:2017-03-11 16:39:30
【问题描述】:

不幸的是,我没有从this open 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,有人知道我必须执行哪些步骤才能使其运行吗?

【问题讨论】:

  • 在类似问题上查看我的answer

标签: haskell opengl nixos


【解决方案1】:

如果你想使用nix-shell:

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

会给你一个知道GLUTghc的shell

我已尝试使用此代码(来自您提到的 wiki page

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 /path/to/shell.nix 任何地方调用不带参数的nix-shell

shell.nix 采用自manual

{ 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)";
}

对于更大的项目,您可能希望使用 cabalstack,但我认为那将是另一回事了。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • nixos 不使用 LSB 文件系统层次结构。这就是问题的全部意义所在。
    • @Turion:我指的不是 LSB 文件系统层次结构,而是 libraries 必须按名称可用的 LSB 集的要求如果它是桌面环境refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Desktop-generic/… - 请注意只指定了库的基本名称,但没有指定它在文件系统树中的位置。顺便说一句:我与一些 NixOS 开发人员是亲密的朋友,并喜欢与他们进行技术讨论(也关于 Nix)。
    【解决方案3】:

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

    nix-shell -p libGL libGLU freeglut cabal install GLUT

    【讨论】:

      猜你喜欢
      • 2019-03-03
      • 2017-05-22
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多