1

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?

Anton Harald
  • 5,772
  • 4
  • 27
  • 61
  • 1
    See my [answer](http://stackoverflow.com/questions/41527061/nixos-haskell-opengl-problems-with-building-and-running-opengl-programs/41588628#41588628) on a similar question. – Soham Chowdhury Jan 11 '17 at 11:13

3 Answers3

2

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.

wizzup
  • 2,361
  • 20
  • 34
0

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

Turion
  • 5,684
  • 4
  • 26
  • 42
  • It's a useful answer for those who want to build their Haskell packages with `cabal` (as opposed to get those packages straight from `nixpkgs`) on NixOS. The only issue is the usual caveat about `cabal install` (since cabal 3 it's not doing what you think it is, refer to the cabal manual for details), so that part is not very useful, but the `nix-shell` part definitely is. – Artem Pelenitsyn May 30 '22 at 13:38
-1

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.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • 1
    nixos does not use the LSB filesystem hierarchy. That's the whole point of the question. – Turion Nov 29 '17 at 17:00
  • @Turion: I was not referring to the LSB filesystem hierachy, but the requirements of the LSB set on which **libraries** must be available **by name** if it's a desktop environment http://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Desktop-generic/LSB-Desktop-generic/opengllib.html – take note that only the basename of the library is specified, but not where it's located in the filesystem tree. BTW: I'm close friends with some of the NixOS devs and enjoy technical discussions with them (also about Nix). – datenwolf Nov 29 '17 at 20:28