Makefile

linux: 几个常用makefile模板

标签: makefilelinuxlibrarycommand
9984人阅读 评论(3) 收藏 举报
分类:

不才,总结个人常用makefile模板,以备后用。

1、编译动态库

  1. #############################################################   
  2. # Makefile for shared library.  
  3. # 编译动态链接库  
  4. #############################################################  
  5. #set your own environment option  
  6. CC = g++  
  7. CC_FLAG = -D_NOMNG -D_FILELINE  
  8.   
  9. #set your inc and lib  
  10. INC =   
  11. LIB = -lpthread -L./ -lsvrtool  
  12.   
  13. #make target lib and relevant obj   
  14. PRG = libsvrtool.so  
  15. OBJ = Log.o  
  16.   
  17. #all target  
  18. all:$(PRG)  
  19.   
  20. $(PRG):$(OBJ)  
  21.     $(CC) -shared -o $@ $(OBJ) $(LIB)  
  22.   
  23. .SUFFIXES: .c .o .cpp  
  24. .cpp.o:  
  25.     $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o  
  26.   
  27. .PRONY:clean  
  28. clean:  
  29.     @echo "Removing linked and compiled files......;  
  30.     rm -f $(OBJ) $(PRG)  

2、编译静态库

  1. #############################################################  
  2. # Makefile for static library.  
  3. # 编译静态链接库  
  4. #############################################################  
  5. #set your own environment option  
  6. CC = g++  
  7. CC_FLAG = -D_NOMNG -D_FILELINE  
  8.   
  9. #static library use 'ar' command   
  10. AR = ar  
  11.   
  12. #set your inc and lib  
  13. INC =   
  14. LIB = -lpthread -L./ -lsvrtool  
  15.   
  16. #make target lib and relevant obj   
  17. PRG = libsvrtool.a  
  18. OBJ = Log.o  
  19.   
  20. #all target  
  21. all:$(PRG)  
  22. $(PRG):$(OBJ)  
  23.     ${AR} rv ${PRG} $?  
  24.   
  25. .SUFFIXES: .c .o .cpp  
  26. .cpp.o:  
  27.     $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o  
  28.   
  29. .PRONY:clean  
  30. clean:  
  31.     @echo "Removing linked and compiled files......"  
  32.     rm -f $(OBJ) $(PRG)  

3、可执行程序

  1. ###########################################  
  2. #Makefile for simple programs  
  3. ###########################################  
  4. INC=  
  5. LIB= -lpthread  
  6.   
  7. CC=CC  
  8. CC_FLAG=-Wall  
  9.   
  10. PRG=threadpooltest  
  11. OBJ=CThreadManage.o CThreadPool.o CThread.o CWorkerThread.o threadpooltest.o  
  12.   
  13. $(PRG):$(OBJ)  
  14.     $(CC) $(INC) $(LIB) -o $@ $(OBJ)  
  15.       
  16. .SUFFIXES: .c .o .cpp  
  17. .cpp.o:  
  18.     $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o  
  19.   
  20. .PRONY:clean  
  21. clean:  
  22.     @echo "Removing linked and compiled files......"  
  23.     rm -f $(OBJ) $(PRG)  


随机组合、举一反三会写出适合项目的makefile

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值