• 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
  • 相关阅读:
    Android音视频之MediaRecorder音视频录制
    Android数据加密之Des加密
    Java设计模式之模板模式(Template )
    Android图片缓存之Glide进阶
    Android图片缓存之初识Glide
    Android图片缓存之Bitmap详解
    Java设计模式之单例模式(Singleton)
    Java设计模式之工厂模式(Factory)
    Java设计模式之建造者模式(Builder)
    Android okHttp网络请求之Retrofit+Okhttp+RxJava组合
  • 原文地址:https://www.cnblogs.com/wind8961/p/5026468.html
Copyright © 2020-2023  润新知