码迷,mamicode.com
首页 > 系统相关 > 详细

Linux学习:Makefile 模板(动态库、静态库、可执行程序)

时间:2019-07-25 14:49:51      阅读:435      评论:0      收藏:0      [点我收藏+]

标签:模板   man   ogr   size   bottom   removing   family   line   splay   

1、编译动态库

    #############################################################   
    # 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、编译静态库

    #############################################################  
    # 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、可执行程序

    ###########################################  
    #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)  

 

Linux学习:Makefile 模板(动态库、静态库、可执行程序)

标签:模板   man   ogr   size   bottom   removing   family   line   splay   

原文地址:https://www.cnblogs.com/blogs-of-lxl/p/11244008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!