0

I have a simple openGL D program that compiles, but I can't get it to link with libglut.a. I've tried a few different command lines:

$ dmd life.d -lglut
$ dmd life.d -L-lglut
$ dmd life.d -L/usr/lib/libglut.a
$ dmd life.d /usr/lib/libglut.a

All of these print the following errors:

life.o:(.data+0x10): undefined reference to `_D1c2gl4glut12__ModuleInfoZ'
life.o:(.data+0x14): undefined reference to `_D1c2gl2gl12__ModuleInfoZ'
life.o: In function `_Dmain':
life.d:(.text._Dmain+0x72): undefined reference to `_D1c2gl4glut8glutInitT1c2gl4glut10pfglutInit'
life.d:(.text._Dmain+0x87): undefined reference to `_D1c2gl4glut19glutInitDisplayModeT1c2gl4glut21pfglutInitDisplayMode'
life.d:(.text._Dmain+0xa1): undefined reference to `_D1c2gl4glut18glutInitWindowSizeT1c2gl4glut20pfglutInitWindowSize'
life.d:(.text._Dmain+0xc2): undefined reference to `_D1c2gl4glut16glutCreateWindowT1c2gl4glut18pfglutCreateWindow'
life.d:(.text._Dmain+0xd7): undefined reference to `_D1c2gl4glut15glutDisplayFuncT1c2gl4glut17pfglutDisplayFunc'
life.d:(.text._Dmain+0xe6): undefined reference to `_D1c2gl4glut12glutMainLoopT1c2gl4glut14pfglutMainLoop'
collect2: ld returned 1 exit status
--- errorlevel 1

Is there a problem with my command lines, or is it something else?

Max
  • 1,295
  • 6
  • 16
  • 31

1 Answers1

1

Those look like mangled symbols from D code. You mentioned on your previous question that you were using some kind of compatibility layer – did you make sure to include the files or libraries from that in your build?

Justin Spahr-Summers
  • 16,893
  • 2
  • 61
  • 79
  • My program imports `c.gl.glut` and `c.gl.gl`. I added `-I/absolute/path/to/glut.d -I/absolute/path/to/gl.d` to the command, and still got the same errors. Is that what you were telling me to do? – Max Dec 26 '10 at 02:11
  • @Max `dmd` is able to locate imports, but doesn't automatically compile them in (for whatever reason). You have to provide all the relevant files when you run it, as in `dmd -L-lglut life.d /absolute/path/to/glut.d /absolute/path/to/gl.d`. – Justin Spahr-Summers Dec 26 '10 at 02:28
  • Good news: It now sees the OpenGL files. Thanks for your help. Bad news: It spat well over a thousand conversion errors at me (something about converting D strings to `char[]`) I think I need to reconsider how I'm going to use OpenGL with D. – Max Dec 26 '10 at 03:45
  • @Max It may be that the code you're using was written for D1, which predates `const` and `immutable` (and thus strings are just `char[]`, instead of `immutable(char)[]`). If that is the case, you can fall back to D1, or update the code to work with D2 as need be. – Justin Spahr-Summers Dec 26 '10 at 03:53
  • 1
    I would recommend that you use Derelict as it has D2 bindings for OpenGL up to version 4. I've written about how to get started with it here: http://poita.org/index.php/d-programming/49-how-to-install-derelict-for-d2 – Peter Alexander Jan 01 '11 at 11:21