Makefile多文件编译

Makefile多文件编译

CC = aarch64-linux-gnu-c++
CFLAGS = #-O2
DBUG = -g
INCLUDE = -I../out/include/ -I../out/include/alize-core/include/ -I../dao/ -I../
LIBS = -lpthread -lsqlite3
LD_FLAG = -L../out/lib
SRCS = $(wildcard *.cpp)  
OBJS = $(patsubst %cpp, %o, $(SRCS))
CGIS = $(patsubst %cpp, %cgi, $(SRCS))
DEP_OBJS = ../dao/sysUserDml.o ../logApi/log.o ../utils/util.o

.PHONY : clean
all: $(CGIS)

.c.o:
    $(CC) $(DBUG) -c $(CFLAGS)  $(INCLUDE) $<  
.cpp.o:
    $(CC) $(DBUG) -c $(CFLAGS)  $(INCLUDE) $<  
%.cgi : %.o
    $(CC) $(DBUG) -o $@ $(OBJS) $(DEP_OBJS) $(LD_FLAG) $(LIBS) $(INCLUDE)

clean :
    -rm -f $(OBJS) $(CGIS)

改进方法

CC = aarch64-linux-gnu-c++
CFLAGS = #-O2
DBUG = -g
INCLUDE = -I../out/include/ -I../out/include/alize-core/include/ -I../dao/ -I../model -I../utils -I.
LIBS = -lpthread -lsqlite3 -lcgic
LD_FLAG = -L../out/lib
SRCS = $(wildcard *.cpp)  
OBJS = $(patsubst %cpp, %o, $(SRCS))
CGIS = $(patsubst %cpp, %cgi, $(SRCS))
DEP_OBJS = ../dao/sysUserDml.o \
            ../dao/userEnrollDml.o \
            ../logApi/log.o \
            ../utils/util.o \
            ../model/userEnroll.o

.PHONY : clean
all:$(CGIS)

clean :
    -rm -f $(OBJS) $(CGIS)

$(CGIS) : %.cgi : %.o 
    $(CC) $(DBUG)  $(DEP_OBJS) $(LD_FLAG) $(LIBS) $(INCLUDE) $< -o $@

$(OBJS): %.o : %.cpp 
    $(CC) -c $(DBUG)  $(CFLAGS)  $(INCLUDE)  $<  

类似使用方式

BIN = test
SRCS = $(wildcard *.cpp)  
OBJS = $(patsubst %cpp, %o, $(SRCS))

.PHONY : clean
all:$(BIN)

clean :
    -rm -f $(OBJS) $(BIN)

$(BIN) : $(OBJS)
    $(CXX) -o $@ $ *.o $(LD_FLAG) $(LIBS)

$(OBJS): %.o : %.cpp 
    $(CXX) -c $(CFLAGS)  $<

你可能感兴趣的:(嵌入式,ubuntu)