Makefile1
src = $(wildcard ./*cpp)
obj = $(patsubst %.cpp, %.o,$(src)) target = test $(target) : $(obj)
g++ $(obj) -o $(target) -I/usr/include/mysql -L/usr/lib/mysql/ -lmysqlclient %.o: %.cpp
g++ -c $< -o $@ -I/usr/include/mysql -L/usr/lib/mysql/ -lmysqlclient .PHONY:clean
clean:
rm -f $(target) $(obj)
Makefile2
CFLAGS = -g
target = test
INCLUDE = -I /usr/include/mysql
lib = -lmysqlclient
dirlib = -L /usr/lib/mysql/ src = $(wildcard *.cpp)
objs = $(patsubst %.cpp,%.o,$(src)) $(target) : $(objs)
g++ $(CFLAGS) $(objs) $(dirlib) $(lib) -o $(target) $(INCLUDE) %.o: %.cpp
g++ $(CFLAGS) $(INCLUDE) $(lib) $(dirlib) -c $< -o $@ .PHONY:clean
clean:
rm -f $(target) $(objs)