维基百科中的 Ocaml OpenGL 示例无法编译
我正在尝试开始一些基本的 Ocaml 编程。 首先,我想从维基百科上运行 OpenGL 示例。 http://en.wikipedia.org/wiki/Ocaml
let _ =
ignore( Glut.init Sys.argv );
Glut.initDisplayMode ~double_buffer:true ();
ignore (Glut.createWindow ~title:"OpenGL Demo");
let angle t = 10. *. t *. t in
let render () =
GlClear.clear [ `color ];
GlMat.load_identity ();
GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. ();
GlDraw.begins `triangles;
List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.];
GlDraw.ends ();
Glut.swapBuffers () in
GlMat.mode `modelview;
Glut.displayFunc ~cb:render;
Glut.idleFunc ~cb:(Some Glut.postRedisplay);
Glut.mainLoop ()
给定的编译器指令
ocamlc -I +lablGL lablglut.cma lablgl.cma simple.ml -o simple
只是导致第 2 行出现错误,表明 Glut.init 未绑定。
我在 cygwin 上运行它,这可能是问题的根源。 但有人知道如何解决吗?
I am trying to get started with some basic Ocaml programming. To start I wanted to get the OpenGL example from wikipedia running. http://en.wikipedia.org/wiki/Ocaml
let _ =
ignore( Glut.init Sys.argv );
Glut.initDisplayMode ~double_buffer:true ();
ignore (Glut.createWindow ~title:"OpenGL Demo");
let angle t = 10. *. t *. t in
let render () =
GlClear.clear [ `color ];
GlMat.load_identity ();
GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. ();
GlDraw.begins `triangles;
List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.];
GlDraw.ends ();
Glut.swapBuffers () in
GlMat.mode `modelview;
Glut.displayFunc ~cb:render;
Glut.idleFunc ~cb:(Some Glut.postRedisplay);
Glut.mainLoop ()
The given compiler directive
ocamlc -I +lablGL lablglut.cma lablgl.cma simple.ml -o simple
Just causes and error on line 2, saying that Glut.init is unbound.
I am running this on cygwin, which could be the source of the problem. But does anybody know how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要先安装 LablGL 绑定,如下维基百科页面上指出。 我不知道在 Cygwin 上执行此操作的最佳方法是什么。
PS OpenGL编程很难说是“基本的Ocaml编程”
You need to install the LablGL bindings first, as indicated on the Wikipedia page. I don't know what is the best way to do this on Cygwin.
P.S. OpenGL programming is hardly "basic Ocaml programming"
在 cygwin + windows 上工作实际上是一种痛苦。 您收到错误的原因很可能是库问题。 它可能就像将 opengl dll 复制到可执行文件的目录中一样简单(先尝试一下)。 但很可能是链接问题。 最好的选择是使用 msvc (有点痛苦)或 mingw 进行编译。 mingw(对于 OPENGL)比让整个工具链在 cygwin 中工作要好得多。 但除此之外我更喜欢 cygwin。
——妮可
This is actually kind of a pain to get working on cygwin + windows. The reason you're getting errors is most likely library issues. It might be as simple as copying the opengl dlls into the directory of your executable (try that first). But mostly likely it's a linking problem. Your best bet is to either compile with msvc (kind of painful) or with mingw. mingw works much better (FOR OPENGL) than getting the whole toolchain working in cygwin. But otherwise I prefer cygwin.
--Nico