读书人

linux: 几个惯用makefile模板

发布时间: 2012-09-21 15:47:26 作者: rapoo

linux: 几个常用makefile模板

不才,总结个人常用makefile模板,以备后用。

1、编译动态库

############################################################# # Makefile for shared library.# 编译动态链接库##############################################################set your own environment optionCC = g++CC_FLAG = -D_NOMNG -D_FILELINE#set your inc and libINC = LIB = -lpthread -L./ -lsvrtool#make target lib and relevant obj PRG = libsvrtool.soOBJ = Log.o#all targetall:$(PRG)$(PRG):$(OBJ)$(CC) -shared -o $@ $(OBJ) $(LIB).SUFFIXES: .c .o .cpp.cpp.o:$(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o.PRONY:cleanclean:@echo "Removing linked and compiled files......;rm -f $(OBJ) $(PRG)

2、编译静态库

############################################################## Makefile for static library.# 编译静态链接库##############################################################set your own environment optionCC = g++CC_FLAG = -D_NOMNG -D_FILELINE#static library use 'ar' command AR = ar#set your inc and libINC = LIB = -lpthread -L./ -lsvrtool#make target lib and relevant obj PRG = libsvrtool.aOBJ = Log.o#all targetall:$(PRG)$(PRG):$(OBJ)${AR} rv ${PRG} $?.SUFFIXES: .c .o .cpp.cpp.o:$(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o.PRONY:cleanclean:@echo "Removing linked and compiled files......"rm -f $(OBJ) $(PRG)

3、可执行程序

############################################Makefile for simple programs###########################################INC=LIB= -lpthreadCC=CCCC_FLAG=-WallPRG=threadpooltestOBJ=CThreadManage.o CThreadPool.o CThread.o CWorkerThread.o threadpooltest.o$(PRG):$(OBJ)$(CC) $(INC) $(LIB) -o $@ $(OBJ).SUFFIXES: .c .o .cpp.cpp.o:$(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o.PRONY:cleanclean:@echo "Removing linked and compiled files......"rm -f $(OBJ) $(PRG)


随机组合、举一反三会写出适合项目的makefile

读书人网 >UNIXLINUX

热点推荐