不幸的是,我没有从this open gl教程中获得一个简单的示例程序。
ghc --make gfx.hs
Could not find module ‘Graphics.UI.GLUT’
[..]
然后我尝试了以下内容:
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
看起来缺少的C库就是问题所在。我正在使用nixOS,有没有人知道我必须做哪些步骤才能让它运行?
答案 0 :(得分:1)
如果您想使用nix-shell
:
$ nix-shell -p 'haskellPackages.ghcWithPackages (p: [ p.GLUT ])'
会为您提供一个知道ghc
GLUT
的shell
我尝试使用此代码(来自您提到的wiki page)
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
但更优选的方法是创建shell.nix
,这样您就不需要记住它。要使用shell.nix
,只需在目录所在的地方调用nix-shell
,不要在任何地方调用nix-shell /path/to/shell.nix
。
shell.nix
来自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)";
}
对于较大的项目,您可能希望使用cabal
或stack
,但我认为这将是另一个故事。
答案 1 :(得分:-1)
在Linux(Nix是Linux发行版)上,LSB指定error: ‘CollisionHandler’ has not been declared
void setCollisionHandler(CollisionHandler* collisionHandler);
是桌面配置文件的一部分。这意味着至少安装了X11客户端库。 libGL
虽然有点特殊,但允许被图形驱动程序安装覆盖。
归结为:为GPU安装图形驱动程序。如果您使用的是Intel或AMD GPU,请安装Mesa驱动程序。如果您的系统有NVidia GPU,我推荐使用专有的NVidia驱动程序。
答案 2 :(得分:-1)
在nixos中,库通常不在cabal
期望的路径上。请尝试以下方法:
nix-shell -p libGL libGLU freeglut
cabal install GLUT