Skip to content

Commit 54e3c2a

Browse files
committed
Fixed dynamic loading of GLU library for recent GHC versions.
1 parent 2fbff38 commit 54e3c2a

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.0.0.3
2+
-------
3+
* Fixed dynamic loading of GLU library for recent GHC versions.
4+
15
2.0.0.2
26
-------
37
* Relaxed upper version bound for `OpenGLRaw`.

GLURaw.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: GLURaw
2-
version: 2.0.0.2
2+
version: 2.0.0.3
33
synopsis: A raw binding for the OpenGL graphics system
44
description:
55
GLURaw is a raw Haskell binding for the GLU 1.3 OpenGL utility library. It is

cbits/HsGLURaw.c

+13-12
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ hs_GLU_getProcAddress(const char *name)
6969
#include <stdlib.h>
7070
#include <dlfcn.h>
7171

72-
#ifndef __APPLE__
73-
#include <stdio.h>
74-
#include <GL/glu.h>
72+
static const char* libNames[] = {
73+
#ifdef __APPLE__
74+
/* Try public framework path first. */
75+
"/Library/Frameworks/OpenGL.framework/OpenGL",
76+
/* If the public path failed, try the system framework path. */
77+
"/System/Library/Frameworks/OpenGL.framework/OpenGL"
78+
#else
79+
"libGLU.so", "libGLU.so.1"
7580
#endif
81+
};
7682

7783
void*
7884
hs_GLU_getProcAddress(const char *name)
@@ -81,18 +87,13 @@ hs_GLU_getProcAddress(const char *name)
8187
static void *handle = NULL;
8288

8389
if (firstTime) {
90+
int i, numNames = (int)(sizeof(libNames) / sizeof(libNames[0]));
8491
firstTime = 0;
85-
/* Get a handle for our executable. */
86-
handle = dlopen(NULL, RTLD_LAZY);
92+
for (i = 0; (!handle) && (i < numNames); ++i) {
93+
handle = dlopen(libNames[i], RTLD_LAZY | RTLD_GLOBAL);
94+
}
8795
}
8896

89-
#ifndef __APPLE__
90-
/* Hack to force linking of GLU on Linux */
91-
FILE *bitbucket = fopen("/dev/null", "w");
92-
fprintf(bitbucket, "%p\n", gluBeginCurve);
93-
fclose(bitbucket);
94-
#endif
95-
9697
return handle ? dlsym(handle, name) : NULL;
9798
}
9899

0 commit comments

Comments
 (0)