不才,总结个人常用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. #set your inc and lib
  9. INC =
  10. LIB = -lpthread -L./ -lsvrtool
  11. #make target lib and relevant obj
  12. PRG = libsvrtool.so
  13. OBJ = Log.o
  14. #all target
  15. all:$(PRG)
  16. $(PRG):$(OBJ)
  17. $(CC) -shared -o $@ $(OBJ) $(LIB)
  18. .SUFFIXES: .c .o .cpp
  19. .cpp.o:
  20. $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o
  21. .PRONY:clean
  22. clean:
  23. @echo "Removing linked and compiled files......;
  24. 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. #static library use 'ar' command
  9. AR = ar
  10. #set your inc and lib
  11. INC =
  12. LIB = -lpthread -L./ -lsvrtool
  13. #make target lib and relevant obj
  14. PRG = libsvrtool.a
  15. OBJ = Log.o
  16. #all target
  17. all:$(PRG)
  18. $(PRG):$(OBJ)
  19. ${AR} rv ${PRG} $?
  20. .SUFFIXES: .c .o .cpp
  21. .cpp.o:
  22. $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o
  23. .PRONY:clean
  24. clean:
  25. @echo "Removing linked and compiled files......"
  26. rm -f $(OBJ) $(PRG)

3、可执行程序

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

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

最新文章

  1. vs2010 安装mvc3
  2. rsync permission denied created directories have no permissions
  3. Getaddrinfo()笔记
  4. 重新想象 Windows 8 Store Apps (62) - 通信: Socket TCP, Socket UDP
  5. table 锁定表头,出滚动对齐
  6. Shell函数参数
  7. Windows7如何在安全模式下卸载驱动(亲测)
  8. 用nginx做代理服务器上网
  9. 时间类处理<1>
  10. 关于debug和release 以及new 和delete
  11. Day2:T4求逆序对(树状数组+归并排序)
  12. Java语言写出水仙花数,
  13. PHP和MySQL Web开发学习笔记介绍
  14. MongoDB学习--安装与管理
  15. django xadmin 1不在可用的选项中
  16. Java 多线程(一)—— 概念的引入
  17. 第五节:Task构造函数之TaskCreationOptions枚举处理父子线程之间的关系。
  18. Fiddler工具使用介绍
  19. 百度统计api 关于搜索引擎返回参数问题
  20. 终于把eShopOnContainer部署成功了。

热门文章

  1. a5站长论坛和s8站长论坛-网上兼职做任务赚钱的两大网站
  2. PB导出规定格式DBF文件
  3. AngularJS 跨站请求- jsonp请求
  4. pch文件的作用和配置
  5. MVC源码解析 - 目录
  6. 浅析ARP协议及ARP攻击
  7. Mysql 5.6 解压版配置方案
  8. RedisDesktopManager
  9. MyBatis 3 与 Spring 4 整合关键
  10. Android开源库loopj的android-async-http的 JsonHttpResponseHandler 存在死循环GC_CONCURRENT