Advertisement

Cannot link SDL+OpenGL example

Started by January 28, 2005 04:23 PM
13 comments, last by Fruny 19 years, 7 months ago
Quote: Original post by Fruny

My heartfelt thanks for the update. I'll try and remember that the next time the question crops up.


Much agreed! I always knew tha .lib order mattered, but I would have never thought about the .o file as well. I rarely use GCC, but this info will come in handy the next time I do. Sneaky sneaky! I'll make me a little post-it note with that hint to remind myself [wink].
Hm, my Linux makefiles do all have the -o listed first before the libraries. Didn't the examples have Makefiles? This is the one I like the best:

CC = g++ -Wall -ansiall:	$(CC) *.cpp -o model -lGL -lGLU `sdl-config --cflags --libs`clean:	@echo Cleaning up...	@rm model	@echo Done.


I only have to change the name (model) and write my file extensions as .cpp.
Advertisement
Quote: Original post by fireside
Hm, my Linux makefiles do all have the -o listed first before the libraries.


It's not the -o but the *.cpp or *.o that matter. The -o option lets you set the name of the output file, and is best left at the end of the line (to avoid trashing some of your files if you accidentally omit the output file parameter).
"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
Thanks. I just figured that was the object files. That makes sense. Does it work the same if you use *.o? I've noticed some makefiles use that, some .cpp. Some both.
Quote: Original post by fireside
Thanks. I just figured that was the object files. That makes sense. Does it work the same if you use *.o? I've noticed some makefiles use that, some .cpp. Some both.


.cpp (or .cc, or .c or .m or ...) files first compile to .o
.o files are then linked together (and with libraries) to make an executable.

Without the -c option, gcc directly performs both operations.

It really depends on your build process.
"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