NixOS,Haskell,opengl:构建和运行openGL程序的问题 [英] NixOS, Haskell, opengl : problems with building and running openGL programs
问题描述
我在使用NixOS的GL时遇到问题:问题似乎已经过时,但2017年仍然没有简单的解决方案!
我是试图使用 Gloss
库构建一个Haskell程序。我已经使用 nix-shell -p mesa
安装了 gloss
以及它需要的所有东西,而且它似乎可以正确构建并且istalled(使用 cabal install
)。但是,如果我使用相同的 nix-shell
构建该程序,则不起作用:
$ nix-shell -p mesa_glu
[nix-shell:] $ ghc --make -O2 SnakePar.hs
链接SnakePar ...
[nix-shell:] $ ./SnakePar
SnakePar:用户错误(未知的GLUT入口glutInit)
在 nix-shell
之外工作时,链接阶段失败:
$ ghc --make -O2 SnakePar.hs
[1的1]编译主(SnakePar.hs,SnakePar.o)
链接SnakePar ...
/ nix / store /< hash> -binutils-2.27 / bin / ld:找不到-lGLU
/nix/store/<hash>-binutils-2.27/bin/ld:找不到-lGL
collect2:错误:ld返回1退出状态
`cc'阶段'连接器'失败。 (退出代码:1)
即使手动安装了 。
$ c> $ nix-env -q
cabal-install-1.24.0.0
ghc-8.0.1
glu-9.0.0
我尝试过使用 freeglut
或 mesa
以同样的方式,但这些(甚至所有在一起)都没有工作。
我缺少什么?
这个问题是相关的,但它没有帮助: nixos + haskell + opengl(先决条件)
解决方案:切换到堆栈后,一切正常。
修正了这个问题,三天后, -user-until-last-week:尝试在
nix-shell
环境中添加 freeglut
,即使用 nix-shell -p mesa freeglut
。 〜/ .stack / stack.yaml
:
nix:
enable:true
packages:[mesa freeglut]
在这种情况下, nix-shell
解决方案不起作用 - 正如我猜测的那样,问题是Stack始终在纯环境中工作,即使从在 nix-shell
中。我在 stack.yaml $ c的
nix
部分尝试了 pure:false
$ c>,但没有奏效。这是现在。
-
mesa
需要提供C头OpenGLRaw
和其他库(这就是为什么你的情况下链接失败,我相信)。
freeglut
提供GLUT绑定(否则您会收到unknown GLUT entry错误)您可能需要将
mesa
更改为其他内容,例如 mesa_glu
。 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!
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)
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)
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
I have tried using freeglut
or mesa
in the same manner, but none of these (or even all together) didn't work.
What am I missing?
This question is relevant but it doesn't help: nixos + haskell + opengl (prerequisites)
Solution: After switching to stack everything works.
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 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.
You may need to change the mesa
there to something else, like mesa_glu
.
这篇关于NixOS,Haskell,opengl:构建和运行openGL程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!