Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"unknown GLU entry gluOrtho2D" using opengl in Haskell

Tags:

haskell

opengl

I'm on Ubuntu 11.10 using ghc version 7.0.3.20110330, running "current-version updates" of nvidia display driver. You can reproduce by running:

curl http://ix.io/1t6 > Stroke.hs; ghc --make Stroke.hs; ./Stroke
...
Stroke: user error (unknown GLU entry gluOrtho2D)

But I can run opengl and it works fine. I tried glxgears and it ran fine and I ran an opengl benchmark and it worked fine as well.

Versions of haskell opengl libs result of running:

for p in OpenGL OpenGLRaw GLURaw; do ghc-pkg latest $p; done

OpenGL-2.4.0.1
OpenGLRaw-1.1.0.1
GLURaw-1.1.0.0
like image 636
mentics Avatar asked Oct 18 '11 10:10

mentics


2 Answers

This is a definite bug. There is a problem with the linker (and I'm not sure if this is specific to 11.10 or to GHC 7.0+). Here's how it was explained to me: the linker essentially decides that, since you're not linking statically to libglut, it will just optimize by not linking your executable to it at all. You can get around this by applying the following patch to GLURaw 1.1.0.0:

diff -ur GLURaw-1.1.0.0.orig/cbits/HsGLURaw.c GLURaw-1.1.0.0/cbits/HsGLURaw.c
--- GLURaw-1.1.0.0.orig/cbits/HsGLURaw.c    2011-05-12 09:02:30.000000000 +1200
+++ GLURaw-1.1.0.0/cbits/HsGLURaw.c 2011-05-11 23:08:10.000000000 +1200
@@ -68,6 +68,9 @@

 #include <stdlib.h>
 #include <dlfcn.h>
+#include <stdio.h>
+#include <GL/glu.h>
+

 void*
 hs_GLU_getProcAddress(const char *name)
@@ -80,6 +83,7 @@
     /* Get a handle for our executable. */
     handle = dlopen(NULL, RTLD_LAZY);
   }
+  printf("%p\n", gluBeginCurve);

   return handle ? dlsym(handle, name) : NULL;
 }
Only in GLURaw-1.1.0.0: dist

Run cabal install on GLURaw after applying this patch, and it should get rid of this problem.

like image 172
rtperson Avatar answered Nov 20 '22 21:11

rtperson


I get it works changing compile step to:

ghc --make Stroke.hs -lGL -lGLU -lglut

I have the versions (I have not installed OpenGLRaw, GLURaw):

cabal list *

* OpenGL
    Default available version: 2.4.0.1
    Installed versions: 2.2.3.0
* OpenGLRaw
    Default available version: 1.1.0.1
    Installed versions: [ Not installed ]
* GLURaw
    Default available version: 1.1.0.0
   Installed versions: [ Not installed ]

EDIT: I'm using Ubuntu 11.04 and GHC 7.0.3 with Haskell Platform 2011.2.0.1

like image 1
Zhen Avatar answered Nov 20 '22 22:11

Zhen