This is an old revision of the document!


Makefiles

Makefiles are very useful to automate compilation of multi-file projects in c/c++ with Linux.

Example

INCLUDE= \
	-I/usr/include \
	-I/usr/local/include \
	-I. \
	`pkg-config --cflags libglade-2.0` 
 
BIN_PATH=./
 
LIBS= \
	`pkg-config --libs libglade-2.0` \
	`pkg-config --libs gtk+-2.0` \
	-export-dynamic
 
LIBS_PATH= \
	-L/lib \
	-L/usr/lib \
	-L/usr/local/lib \
	-L.
 
COMPILO=g++
 
FLAGS= -c -g -Wall -ansi -pedantic
#FLAGS= -c -ansi -pedantic
 
OBJ= \
	file1.o \
	file2.o
 
 
 
 
# cibles :
 
monprog: $(OBJ)
	$(COMPILO) -o $(BIN_PATH)monprog $(OBJ) $(LIBS_PATH) $(LIBS)
 
clean : 
	rm -f *.o
 
clear : 
	rm -f *.o monprog
 
# compilation des sources :
 
file1.o : file1.cpp file1.h
	$(COMPILO) $(FLAGS) $(INCLUDE) -o file1.o file1.cpp
 
file2.o : file2.cpp file2.h
	$(COMPILO) $(FLAGS) $(INCLUDE) -o file2.o file2.cpp

pkg-config

When using libraries, pkg-config is very useful :

pkg-config --cflags libxml++-2.6
pkg-config --libs libxml++-2.6

auto-tools

programming/makefiles.1197848675.txt.gz · Last modified: 2013/09/19 16:43 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0