本文介绍了nixos + haskell + opengl(先决条件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我没有从开放式gl教程中获得一个简单的示例程序。 / p>

Unfortunately, I'm not getting a simple example program from this open gl tutorial to work.

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

然后我尝试了以下内容:

Then I tried the following:

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,是否有人知道为了让它正常运行,我必须执行哪些步骤?

It looks like the missing C library is the problem. I'm using nixOS, does anybody know which steps I'd have to do in order to get this running?

推荐答案

如果你希望使用 nix-shell

If you want to use nix-shell:

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

会给你一个shell ghc 知道 GLUT

will give you a shell with ghc that know GLUT

我试过此代码(来自您提到的)

I've try with this code (from the wiki page you mentioned)

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 c> nix-shell /path/to/shell.nix 任何地方。


But the more preferable way is to create shell.nix so you don't need to remember it. To use shell.nix, just call nix-shell without argument in the directory where it is or nix-shell /path/to/shell.nix anywhere.

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 ,但我认为这将是另一回事。


For a bigger project you might want to use cabal or stack but I think that would be another story.

这篇关于nixos + haskell + opengl(先决条件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 03:07