话不多说,请看:

我的项目有的目录结构有:

dirls/
├── include
│   └── apue.h
├── lib
│   ├── error.c
│   ├── error.o
│   └── Makefile
├── src
│   ├── dirls.c
│   ├── dirls.out
│   └── Makefile
└── test_client

而我的Makefile模板代码如下:

SRCS = $(wildcard *.c ../lib/*.c)    #wildcard把 指定目录 ./ 和 ../lib 下的所有后缀是c的文件全部展开。

OBJS = $(SRCS:.c = .o)    #OBJS将$(SRCS)下的.c文件转化为.o文件

CC = gcc   #代表所使用的编译器

INCLUDES = -I../include \   #头文件查找路径
-I. \ LIBS = -L../lib \ #链接库查找地址 CCFLAGS = -g -Wall -O0 #附加参数 OUTPUT = dirls.out #输出程序名称 all:$(OUTPUT) $(OUTPUT) : $(OBJS)
$(CC) $^ -o $@ $(INCLUDES) $(LIBS) %.o : %.c
$(CC) -c $< $(CCFLAGS) clean:
rm -rf *.out *.o #清除中间文件及生成文件 .PHONY:clean

另外附上别的网站的几个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)

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)

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)

最新文章

  1. MyBatis配置文件解析
  2. 0518 Scrum 项目 5.0
  3. Hark的数据结构与算法练习之桶排序
  4. Xcode:Foundation框架找不到,或者是自动提示出现问题
  5. 使用struts2实现文件上传
  6. JSOI2007建筑抢修
  7. yii 的mvc工作流
  8. java抽象类和接口的区别(转载)
  9. Java面试题—初级(7)
  10. imgtobase64
  11. 解决使用display:inline-block时元素间隔问题
  12. InnoDB中锁的算法(1)
  13. Vue 项目集合
  14. [Windows Azure] Manage the Availability of Virtual Machines
  15. 使用 mysqldump 备份时的一些参数
  16. 【屌丝程序的口才逆袭演讲稿50篇】第十三篇:爱迪生欺骗了我们!【张振华.Jack】
  17. exception javax.crypto.BadPaddingException: Given final block not properly padded
  18. unity5 where is &quot;Edit-&gt;Render Settings&quot;?
  19. Codeforces Round #304 (Div. 2) C. Soldier and Cards 水题
  20. 使用BeanShell 对比取出来的值

热门文章

  1. 采用指数退避算法实现ajax请求的重发,全部完成时触发回调函数
  2. Scala学习笔记(五):类和对象
  3. this,this,再次讨论javascript中的this,超全面
  4. 疯狂的Java算法——插入排序,归并排序以及并行归并排序
  5. windows API 开发飞机订票系统 图形化界面 (二)
  6. 1、面向对象以及winform的简单运用(开篇)
  7. ibatis中的$和#的区别
  8. java多线程-Semaphore信号量使用
  9. Java基础-父类-子类执行顺序
  10. 【CodeForces 618C】Constellation