Advertisement

Cannot link SDL+OpenGL example

Started by January 28, 2005 04:23 PM
13 comments, last by Fruny 19 years, 7 months ago
I am trying to compile the SDL+OpenGL example that can be found in the SDL documentation (I got it from the Windows SDLRef.chm). It is also here http://www.cs.vu.nl/~tverweij/stuff/example.c I am using MinGW (currently the most recent MinGW-3.2.0-rc-3.exe installation) to compile & link, (I've also tried the older MinGW-3.1.0-1.exe release). I installed SDL from the SDL-devel-1.2.8-mingw32.tar.gz archive. I also tried 1.2.7, since I read that there were some problems with 1.2.8. Unfortunately this does not make a difference. Compiling works fine. Trying to link without any libraries (obviously) generates the following errors: http://www.cs.vu.nl/~tverweij/stuff/errors_more.txt If I add all libs I think are required, only a few of the errors are gone: http://www.cs.vu.nl/~tverweij/stuff/errors_less.txt Most of the link errors remain there. Many SDL and OpenGL related functions cannot be found for some reason. Only SDL_Init, SDL_Quit and SDL_GetError suddenly seem to be found, but all of the other references are still undefined. The linker does not complain about any of the libraries. If I change any of the options to -lblahblah, then it does complain, so I guess the libraries are found. If anyone has any idea, plz help. :-)
Different platform (Linux, GCC 3.4.3, SDL 1.2.7), compiles, links and runs without a hitch (gcc -lGL -lGLU -lSDLmain -lSDL example.o -o example)

Sorry. [sad]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Hmm, all I can say is the order in which you link the libraries may be important.

I got it to compile on Windows with the following libraries linked in this order:

-lmingw32
-lSDLmain
-lSDL
-lopengl32
-lglu32

Edit: Can't seem to replicate your errors, no matter what order I have the libraries in, sorry :/
the rug - funpowered.com
Quote: Original post by The Rug
Hmm, all I can say is the order in which you link the libraries may be important.


It may be. I've had to use linkers for which, when library A depends on library B, library B should be listed after library A, because it will then come and 'plug the holes' left by those functions library A needs but does not provide. And yes, if two libraries are mutually dependent, one of them has to be listed twice.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Weird. Perhaps I missed some important step in installing MinGW? Do I need to do more than just add the MinGW/bin directory to my PATH variable once the installer is finished?
I've just started playing around with opengl/sdl, but what about the code in the example? In some of the examples I've seen it uses an include GL/gl.h, which might not work in windows because they use the opposite backslash from unix. Unless it's a window's example, of course.
Advertisement
Correct me if I'm wrong, but if that would be the problem then I wouldn't be able to compile the program to an object file, right? By using the command
gcc -c example.c
I get the file example.o, so the program compiles. Since this works, I can assume all #includes work as well (and slashes are properly converted to backslashes by the compiler). The problem lies in the next step: linking the object file to produce an executable. For some reason the linker thinks many function calls are undefined references, even though I include all required libraries (that provide an implementation of those functions) using command line switches.
Yeah. It would show up in compile. It must be your dll files aren't in system, I'm out of the whole Windows thing for a month now and am losing touch.
Well here's the solution from someone on the MinGW forums at sf.net:
Quote: Original post by Daniel K. O. - danielosmari (on sf.net)
Put the .o files BEFORE the libraries. The order IS important. When GCC needs a symbol, it'll search for it in the next objects/libs passed as arguments.
In the way you are doing, it's skipping the SDL/OpenGL symbols because they weren't needed; only at the end GCC realizes it needs those symbols for the .o.


It seems that not only the order of the libraries matter, but also the object files need to be listed before the libraries. Thank you all for your replies. My problem seems to be solved now. Back to coding! :-)
Quote: Original post by TimV
Well here's the solution from someone on the MinGW forums at sf.net:
Quote: Original post by Daniel K. O. - danielosmari (on sf.net)
Put the .o files BEFORE the libraries. The order IS important. When GCC needs a symbol, it'll search for it in the next objects/libs passed as arguments.
In the way you are doing, it's skipping the SDL/OpenGL symbols because they weren't needed; only at the end GCC realizes it needs those symbols for the .o.


It seems that not only the order of the libraries matter, but also the object files need to be listed before the libraries.


My heartfelt thanks for the update. I'll try and remember that the next time the question crops up.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement