[Haskell-cafe] Linker errors to OpenGL with GHC 6.10.1

Pekka Karjalainen p3k at iki.fi
Thu Nov 13 02:18:21 EST 2008


2008/11/13 Greg Fitzgerald <garious at gmail.com>:
> Do you know how I can fix these linker errors?
>
> C:\projects\fun>cat HelloWorld.hs
>
> import Graphics.Rendering.OpenGL
> import Graphics.UI.GLUT
> main = do
>   (progname, _) <- getArgsAndInitialize
>   createWindow "Hello World"
>   displayCallback $= clear [ColorBuffer]
>   mainLoop
>
> C:\projects\fun>ls lib
> GlU32.Lib
> glut32.lib
> OpenGL32.Lib
> glut.def
> glut32.dll
>
> C:\projects\fun>ghc -Llib -lglut32 -lglu32 -lopengl32 HelloWorld.hs --make
> Linking HelloWorld.exe ...
> C:\Program
> Files\Haskell\GLUT-2.1.1.2\ghc-6.10.1/libHSGLUT-2.1.1.2.a(Begin.o):fake:(.text+0x1cb):
> undefined reference to `glutGet'
[...]

> Thanks,
> Greg

I'm assuming this is on Windows because of C:\...

These kinds of linker errors happened to me when I built libHSGLUT
with a wrong type of calling convention (by accident). There are two
callconvs, and they are called stdcall and ccall on the Haskell side.
The 'runhaskell setup configure' step is supposed to detect the
correct one to use, so you should run it and then grep for lines with
CALLCONV. They should say stdcall on Windows. If you find them saying
ccall, that's likely the cause of all the linker errors. (Most Windows
dynamic libraries use stdcall, but for extra configuration fun OpenAL
uses ccall.)

If this is the problem, you can change the offending ccall in the
configuration files to stdcall and rebuild the library. Grepping for
CALLCONV will also show the places you need to change this way.

In my case the wrong configuration came from using the sh program from
Cygwin. With the MSYS variety there was no problem. To be exact, it
came down to the $host variable checked by the configuration script.

Pekka


More information about the Haskell-Cafe mailing list