PDA

View Full Version : How to compile OpenGL program on Linux?



07-11-2002, 06:07 AM
Hi! I have Mesa 4.0.3 library and I want to compile a program in c/c++ language which uses this library. What command do I have to type in? I know it should be like this: "gcc(or g++) -o name_of_the_program program.c", but what else should I write? Name of the library? -l option or something? Please help! I want to start learning OpenGL as fast as it is possible. linuxer

07-11-2002, 09:02 PM
That question was recently answered http://www.opengl.org/discussion_boards/ubb/Forum4/HTML/000711.html

Some addtional tips:
- info gcc for gcc documentation
- check if you can compile with a shorter command
- if you have a nvidia card will you find great drivers on the nvidia site
- I always use -Wall to turn on all warnings

pkaler
07-13-2002, 07:19 PM
Here's my makefile. Hopefully you'll find it usefull. The first three lines is what you are most likely to change. It figures out dependencies by itself, as long as you give your files .cpp and .h extensions.

If you haven't used makefiles before, there are a whole bunch of targets:
make
make all
make clean
make explain
etc, etc

Do a search on google you should be able to find a tutorial somewhere.

Btw, it would be much appreciated if anyone wants to contribute any makefile tips. In particular, I haven't been able to figure out how to move by .o and .d files to a debug/ subdirectory, kind of like how VC++ does.




EXECUTABLE = poop
CPPFLAGS = -ggdb3 -Wall
LIBS = -lpthread -lGL -lGLU -lglut
#################################################
CC = g++
SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
DEPS := $(patsubst %.cpp,%.d,$(SRCS))
#################################################
all: $(EXECUTABLE)

$(EXECUTABLE): $(DEPS) $(OBJS)
$(CC) -o $(EXECUTABLE) $(OBJS) $(LIBS)

%.d: %.cpp
$(CC) -M $(CPPFLAGS) $< > $@
$(CC) -M $(CPPFLAGS) $< | sed s/\\.o/.d/ > $@

%.d: %.h
$(CC) -M $(CPPFLAGS) $< > $@
$(CC) -M $(CPPFLAGS) $< | sed s/\\.o/.d/ > $@
clean:
-rm $(OBJS) $(EXECUTABLE) $(DEPS) *~

explain:
@echo "--------Some Info--------"
@echo "Executable name: $(EXECUTABLE)"
@echo "Source files: $(SRCS)"
@echo "Object files: $(OBJS)"
@echo "Dependency files: $(DEPS)"

depends: $(DEPS)
@echo "Dependencies updated"

-include $(DEPS)

run: all
./$(EXECUTABLE)

debug: all
gdb $(EXECUTABLE)

clean-emacs:
rm *~