g++编译的makefile模板库和脚本

  编译C++文件,特别是多文件的时候,经常要找模板,这里为了后面方便,就自己做了一个模板。

  makefile模板:Makefile

# Object files to either reference or create                          
#OBJECTS = Proj2.o Blackjack.o Deck.o Card.o Hand.o Player.o           
OBJECTS = phash.o
# The executable file that will be created at the end                 
EXEC = aphash

#lib 
LIBS = $(shell pkg-config --libs opencv)

# The flags to use for compilation                                    
FLAGS = -Wall
# The code compiler to use for compilation                            
CC = g++

# Perform action on all object files (May or may not exist)           
all: $(OBJECTS)
        $(CC) $(FLAGS) -o $(EXEC) $(OBJECTS) $(LIBS)

  编译脚本模板:build.sh

make > log.txt 2>&1

if [ $? -eq 0 ];then
        echo "build success"
else
        echo "budild failed and call log.txt"
        cat log.txt | grep "error:*"
fi
原文地址:https://www.cnblogs.com/dylancao/p/9138945.html