NixOS, Haskell, opengl : problems with building and running openGL programs

别等时光非礼了梦想. 提交于 2019-11-29 06:52:51

I just fixed this, after three days of, well, being another not-happy Arch-user-until-last-week: try adding freeglut to the nix-shell environment, i.e. use nix-shell -p mesa freeglut.

For stack users stumbling upon this answer, add this to ~/.stack/stack.yaml:

nix:
  enable: true
  packages: [mesa freeglut]

The nix-shell solution doesn't work in this case -- the problem, as I'm guessing, is that Stack always works inside a pure environment even if run from inside a nix-shell. I did try pure: false in the nix section of stack.yaml, but that didn't work. This does, for now.

  • mesa is required to provide the C headers for OpenGLRaw and other libraries (and this is why linking fails in your case, I believe).
  • freeglut provides the GLUT bindings (you'll get the "unknown GLUT entry" error otherwise) required at runtime.

You may need to change the mesa there to something else, like mesa_glu.

The following helped me:

with import <nixpkgs> {};
pkgs.stdenv.mkDerivation rec {
  name = "dev-env";
  buildInputs = with pkgs; [
    mesa
    freeglut
  ];
  LD_LIBRARY_PATH = with pkgs; "${freeglut}/lib";
}

Copy this to shell.nix, enter the environment with nix-shell and run compiled executable inside the env.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!