繁体   English   中英

nixos + haskell + opengl(先决条件)

[英]nixos + haskell + opengl (prerequisites)

不幸的是,我没有从这个开放的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,有人知道要执行此步骤必须执行哪些步骤吗?

如果要使用nix-shell

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

会给你用ghc知道GLUT的外壳

我尝试使用此代码(来自您提到的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)";
}

对于较大的项目,您可能需要使用cabalstack但是我认为那是另一回事了。

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

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

在nixos中, cabal通常期望在它们所在的路径上通常不提供库。 请尝试以下操作:

nix-shell -p libGL libGLU freeglut cabal install GLUT

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM