makefile模板

来源:互联网 发布:禁止软件安装的软件 编辑:程序博客网 时间:2024/06/11 06:50

可执行文件

###########################################  #Makefile for simple programs  ###########################################  INC=  LIB= -lpthread    CC=gcc  CC_FLAG=-Wall    PRG=test  OBJ=test.o    $(PRG):$(OBJ)      $(CC) $(INC) $(LIB) -o $@ $(OBJ)                    .SUFFIXES: .c .o  .c.o:      $(CC) $(CC_FLAG) $(INC) -c $*.c -o $*.o    .PRONY:clean  clean:      @echo "Removing linked and compiled files......"      rm -f $(OBJ) $(PRG)  


windows执行结果就是test.exe  

Linux执行结果就是test


动态库

#############################################################   # Makefile for shared library.  #############################################################  #set your own environment option  CC = gcc  CC_FLAG =    #set your inc and lib  INC =   LIB = -lpthread -L./    #make target lib and relevant obj   PRG = libtest.so  OBJ = test.o    #all target  all:$(PRG)    $(PRG):$(OBJ)      $(CC) -shared -o $@ $(OBJ) $(LIB)  .SUFFIXES: .c .o  .c.o:      $(CC) $(CC_FLAG) $(INC) -c $*.c -o $*.o    .PRONY:clean  clean:      @echo "Removing linked and compiled files......;      rm -f $(OBJ) $(PRG) 




静态库

#############################################################  # Makefile for static library.  #############################################################  #set your own environment option  CC = gcc  CC_FLAG =    #static library use 'ar' command   AR = ar    #set your inc and lib  INC =   LIB = -lpthread -L./    #make target lib and relevant obj   PRG = libtest.a  OBJ = test.o    #all target  all:$(PRG)    $(PRG):$(OBJ)      ${AR} rv ${PRG} $?  .SUFFIXES: .c .o  .c.o:      $(CC) $(CC_FLAG) $(INC) -c $*.c -o $*.o  .PRONY:clean  clean:      @echo "Removing linked and compiled files......"      rm -f $(OBJ) $(PRG)


0 0
原创粉丝点击