您的位置:首页 > 运维架构 > Linux

linux: 几个常用makefile模板

2014-11-20 09:42 253 查看
原文地址:http://blog.csdn.net/lzx_bupt/article/details/7988192

================================================================================================================

1、编译动态库

[plain] view
plaincopy

#############################################################   

# Makefile for shared library.  

# 编译动态链接库  

#############################################################  

#set your own environment option  

CC = g++  

CC_FLAG = -D_NOMNG -D_FILELINE  

  

#set your inc and lib  

INC =   

LIB = -lpthread -L./ -lsvrtool  

  

#make target lib and relevant obj   

PRG = libsvrtool.so  

OBJ = Log.o  

  

#all target  

all:$(PRG)  

  

$(PRG):$(OBJ)  

    $(CC) -shared -o $@ $(OBJ) $(LIB)  

  

.SUFFIXES: .c .o .cpp  

.cpp.o:  

    $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o  

  

.PRONY:clean  

clean:  

    @echo "Removing linked and compiled files......;  

    rm -f $(OBJ) $(PRG)  

2、编译静态库

[plain] view
plaincopy

#############################################################  

# Makefile for static library.  

# 编译静态链接库  

#############################################################  

#set your own environment option  

CC = g++  

CC_FLAG = -D_NOMNG -D_FILELINE  

  

#static library use 'ar' command   

AR = ar  

  

#set your inc and lib  

INC =   

LIB = -lpthread -L./ -lsvrtool  

  

#make target lib and relevant obj   

PRG = libsvrtool.a  

OBJ = Log.o  

  

#all target  

all:$(PRG)  

$(PRG):$(OBJ)  

    ${AR} rv ${PRG} $?  

  

.SUFFIXES: .c .o .cpp  

.cpp.o:  

    $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o  

  

.PRONY:clean  

clean:  

    @echo "Removing linked and compiled files......"  

    rm -f $(OBJ) $(PRG)  

3、可执行程序

[plain] view
plaincopy

###########################################  

#Makefile for simple programs  

###########################################  

INC=  

LIB= -lpthread  

  

CC=CC  

CC_FLAG=-Wall  

  

PRG=threadpooltest  

OBJ=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:clean  

clean:  

    @echo "Removing linked and compiled files......"  

    rm -f $(OBJ) $(PRG)  

随机组合、举一反三会写出适合项目的makefile
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: