Makefiles are the way to go in UNIX-like environments. Everybody has their own preferred makefile template. If you want one to start with, you could try this:
Code:
CXX = g++
# List any extra include paths you need on the following line, in the form -I<path>
INCLUDE =
# List any extra macro definitions you need on the following line, in the form -D<macro>
DEFINE =
# Comment the following line to disable debug symbols
DEBUGFLAGS = -g
# Uncomment the following line to enable optimization
#OFLAGS = -O3
# Uncomment the following line to enable gprof profiling
#PROFFLAGS = -pg
CXXFLAGS = $(INCLUDE) $(DEFINE) $(DEBUGFLAGS) $(OFLAGS) $(PROFFLAGS)
# List any libraries you want to link against on the following line, in the form -L<path> or -l<lib>
LIBS =
LDFLAGS = $(LIBS) $(PROFFLAGS)
# List all your .cpp files on the following line
SRCS = a.cpp b.cpp c.cpp
# List all your .h files on the following line
HDRS = a.h b.h c.h
OBJS = $(SRCS:.cpp=.o)
# Choose the name of the program file
TARGET = MyProgram
.PHONY: all clean
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) -o $@ $^ $(LDFLAGS)
clean:
rm -f $(TARGET)
rm -f $(OBJS)
.dep: $(SRCS) $(HDRS)
$(CXX) -M $(CXXFLAGS) $(SRCS) > .dep
-include .dep
Place the above into a file called "Makefile" (with capital 'M'), tweak as indicated, then run "make".
Note that I typed that from memory, so it may contain bugs, though I did pay attention while writing it