Makefiles and Mac OS X... |
23 September 2004 |
Compiling Mesa Demos.
Today I had occasion to download and compile the
Mesa
demos to do a performance comparison of some demos on similar video cards.
I will not go into the actual performance comparison,
this is about compiling projects from a standard makefile. The downloaded archive
was simply extracted to my Desktop folder.
The Mesa Demos
directory contains a large number of OpenGL demos. The only ones we were
interested in are fire, teapot and ipers.
Expecting to just type make in ~/Desktop/Mesa-6.1/progs/demos/ I was
surprised to see several pages of errors scroll by in my console window!
File not found...
The "file not found" errors occurred in all source files that were needed
to build the three demos we wanted as well as ~/Desktop/Mesa-6.1/include/GL/glut.h.
Obviously this was easily fixed by removing the GL/ from
the #include directives in the following files:
- fire.c
- ipers.c
- teapot.c
- readtex.c
- readtex.h
- ../../GL/glut.h
We also had to change both occurrances of
GL_RESCALE_NORMAL_EXT to
GL_RESCALE_NORMAL in ipers.c.
Makefile.
The Makefile had to be edited also since we did not want to use the glut
header that was supplied in the archive.
After removing the reference to the included include directory from the
INCDIR variable in the Makefile we saw
some more errors. This time the OpenGL
and GLUT libraries were not found. After a quick bit of Googling we saw that we
needed to add the relevant frameworks to the Makefile.
First we added the frameworks' header paths to the INCDIR variable:
INCDIR = -I/System/Library/Frameworks/OpenGL.framework/Headers \
-I/System/Library/Frameworks/GLUT.framework/Headers
To make sure the right libraries were linked to we changed the OSMESA_LIBS variable to:
OSMESA_LIBS = \
-L/System/Library/Frameworks/OpenGL.framework/Libraries \
-lGLU -framework GLUT -lGL -framework OpenGL
The final error we needed to fix was a curly one! We received the following error:
ld: /usr/lib/crt1.o illegal reference to symbol: __objcInit defined in indirectly
referenced dynamic library /usr/lib/libobjc.A.dylib
Again Google to the rescue, we found many many answers with the exact same solution: "add -lobjc".
So we did! We added -lobjc to the OSMESA_LIBS variable.
The __objcInit gave it away: the GLUT framework needed to be
linked with the Cocoa framework (objc).
Finally...
Finally we only needed to fix the actual command line from:
.c: $(LIB_DEP) $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
to:
.c: $(LIB_DEP) $(CC) $(INCDIR) $(CFLAGS) $< $(OSMESA_LIBS) -o $@
Now we were able to run make to compile and link the demos we wanted.
Hint:
After modifying the readtex.c and readtex.h file, back them up to a directory
called utils in the progs directory. When you do a make clean these 2 files are removed from
the progs/demos directory by the Makefile.
Instead of making a backup you can also just remove the line -rm -f readtex.[ch] from the clean target.
Why?
Why do I have to modify source files? Why do I have to modify a standard makefile? It should be possible to take a project
and at the very least not have to edit out all the "GL/" prefixes. Very annoying!
If you have anything to add or you have a question regarding this process please do not hesitate to email me at
jeroen at happymakinggames dot com
|