问题
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
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?
回答1:
If you want to use nix-shell
:
$ nix-shell -p 'haskellPackages.ghcWithPackages (p: [ p.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
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
adopted from the 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)";
}
For a bigger project you might want to use cabal
or stack
but I think that would be another story.
回答2:
On Linux (Nix is a Linux distribution) the LSB specifies that libGL
is part of the desktop profile. That means having at least the X11 client libraries installed. libGL
is a bit special though and is permitted to be overridden by the graphics driver installation.
What this boils down to is: Install the graphics drivers for your GPU. If you're using an Intel or a AMD GPU install the Mesa drivers. If your system has a NVidia GPU I recommend the proprietary NVidia drivers.
回答3:
In nixos, libraries aren't usually available on the path where cabal
expects them to be. Try the following:
nix-shell -p libGL libGLU freeglut
cabal install GLUT
来源:https://stackoverflow.com/questions/40310973/nixos-haskell-opengl-prerequisites