g++ example.cpp
a.out
g++ -o example example.cpp
example
make example
will do the same thing.
Makefile
all: example
make
to compile our executable.
-o example
is an example of a compiler option or in general a command line argument.
-g -O2 -Wall -Wextra -Werror
g++ -Wuninitalized uninit.cpp -o uninit
g++ -Wall -Wextra badLoop.cpp -o badLoop
-Werror
turns all warnings into errors.
g++ -Wall -Wextra -Werror badLoop.cpp -o badLoop
# add the names of the programs you want to compile here OBJS = CXXFLAGS = -g -O2 -Wall -Wextra -Werror all: ${OBJS} # the rm line starts with a tab. clean: rm -f ${OBJS} *.o
OBJS = uninit badParam
uninit
and badParam
rm -f *.o ${OBJS}
make
will build any executables listed in OBJS
make clean
will remove the executables and any .o files.
make -n
will show what will happen.
make anything
will build anything with the flags specified in the Makefile