linux 常用makefile模板
2016-06-21 16:30
781 查看
1、编译动态库
[plain] view
plain copy
#############################################################
# 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、编译静态库
[plain] view
plain copy
#############################################################
# 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、可执行程序
[plain] view
plain copy
###########################################
#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)
随机组合、举一反三会写出适合项目的makefile
[plain] view
plain copy
#############################################################
# 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、编译静态库
[plain] view
plain copy
#############################################################
# 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、可执行程序
[plain] view
plain copy
###########################################
#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)
随机组合、举一反三会写出适合项目的makefile
相关文章推荐
- (转)Linux NUMA引发的性能问题
- 每天一个Linux命令(02)--cd命令
- (转)Linux常用性能检测命令
- Linux驱动修炼之道-SPI驱动框架源码分析(上)【转】
- (转)《linux性能及调优指南》 3.3 内存瓶颈
- 从串口驱动的移植看linux2.6内核中的驱动模型 platform device & platform driver【转】
- 【linux】top命令详解
- GNU Linux核心命令和工具的源代码路径
- centos6.5 安装svn可视化管理工具 if.svnadmin
- redhat下的环境搭建
- Linux常用多线程函数
- CentOS安装sun java
- 如何在linux下查看JDK是多少位的
- linux搭建NFS支持windws2008访问
- LINUX下目标文件的BSS段、数据段、代码段
- Linux命令大全
- linux ln
- CentOS 7 —— /etc/rc.local 开机不执行 - 解决方法
- 准备把平台挪到linux
- centos minimal虚拟机测试javaee配置