linux: 幾個常用makefile模板(動態庫、靜態庫、可執行程序)


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)  
View Code

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)  
View Code

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)  
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM