NixOS、Haskell、opengl:构建和运行 openGL 程序的问题 [英] NixOS, Haskell, opengl : problems with building and running openGL programs
问题描述
我在 NixOS 上遇到 GL 问题:这个问题似乎很老了,但在 2017 年仍然没有直接的解决方案!
I'm experiencing a problem with GL on NixOS: the problem seems to be old, but there is still no straightforward solution yet in 2017!
我正在尝试使用 Gloss
库构建 Haskell 程序.我已经使用 nix-shell -p mesa
安装了 gloss
和它需要的一切,它似乎已经正确构建和安装(使用 cabal install
).但是,如果我在同一个 nix-shell
中构建程序,则它不起作用:
I'm trying to build a Haskell program using the Gloss
library. I have installed gloss
and everything it needs using the nix-shell -p mesa
and it seems to be properly build and istalled (using cabal install
). However if I build the program in the same nix-shell
it doesn't work:
$ nix-shell -p mesa_glu
[nix-shell:]$ ghc --make -O2 SnakePar.hs
Linking SnakePar ...
[nix-shell:]$ ./SnakePar
SnakePar: user error (unknown GLUT entry glutInit)
在 nix-shell
之外工作时,链接阶段失败:
While working outside of a nix-shell
the linking stage failes:
$ ghc --make -O2 SnakePar.hs
[1 of 1] Compiling Main ( SnakePar.hs, SnakePar.o )
Linking SnakePar ...
/nix/store/<hash>-binutils-2.27/bin/ld: cannot find -lGLU
/nix/store/<hash>-binutils-2.27/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
即使我已经通过 nix-env -iA
手动安装了 glu
库,也会发生这种情况.
This happens even though I have manually installed the glu
library via nix-env -iA
.
$ nix-env -q
cabal-install-1.24.0.0
ghc-8.0.1
glu-9.0.0
我曾尝试以相同的方式使用 freeglut
或 mesa
,但这些(甚至全部)都不起作用.
I have tried using freeglut
or mesa
in the same manner, but none of these (or even all together) didn't work.
我错过了什么?
这个问题是相关的,但没有帮助:nixos + haskell + opengl(先决条件)一个>
This question is relevant but it doesn't help: nixos + haskell + opengl (prerequisites)
解决方案:切换到堆栈后一切正常.
Solution: After switching to stack everything works.
推荐答案
我刚刚解决了这个问题,三天后,好吧,作为另一个不开心的 Arch 用户直到上周: 尝试将 freeglut
添加到 nix-shell
环境中,即使用 nix-shell -p mesa freeglut
.
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
.
对于 stack
用户偶然发现这个答案,将其添加到 ~/.stack/stack.yaml
:
For stack
users stumbling upon this answer, add this to ~/.stack/stack.yaml
:
nix:
enable: true
packages: [mesa freeglut]
nix-shell
解决方案在这种情况下不起作用——我猜测的问题是 Stack 总是在纯环境中工作,即使从 nix-shell
.我确实在 stack.yaml
的 nix
部分尝试了 pure: false
,但是没有用.暂时是这样.
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
需要为OpenGLRaw
和其他库提供 C 头文件(我相信这就是链接失败的原因).freeglut
提供运行时所需的 GLUT 绑定(否则您将收到未知的 GLUT 条目"错误).
mesa
is required to provide the C headers forOpenGLRaw
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.
您可能需要将那里的 mesa
更改为其他内容,例如 mesa_glu
.
You may need to change the mesa
there to something else, like mesa_glu
.
这篇关于NixOS、Haskell、opengl:构建和运行 openGL 程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!