linux: 几个常用makefile模板
2015-10-20 18:47
585 查看
不才,总结个人常用makefile模板,以备后用。
1、编译动态库
[plain]
view plaincopy
#############################################################
# 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 plaincopy
#############################################################
# 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 plaincopy
###########################################
#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
1、编译动态库
[plain]
view plaincopy
#############################################################
# 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 plaincopy
#############################################################
# 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 plaincopy
###########################################
#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运维工程师工作手册
- linux畅聊系统乱码问题
- 老男孩解决vmware克隆Centos6.4虚拟机网卡无法启动问题
- Linux常用命令
- CentOS下调整系统时区
- linux问题-Centos 安装Sublime text 3
- Comet4J推技术在SSHE三大框架中应用-linux下亲测可用
- Install GlassFish Server on CentOS
- Linux 内核空间与用户空间
- linux中crontab实现以秒执行任务
- Linux下WPS相关命令——et,wps,wpp
- Linux中xargs的用法
- linux下导入、导出mysql数据库命令
- Redhat Enterprise Linux 6 (RHEL 6) YUM源切换至阿里云的CentOS 6 YUM源
- Linux + Busybox 最小Linux
- linux虚拟地址空间你真的理解了吗?
- Centos 6.5 安装 ionCube PHP Loader
- centos6.5下安装zabbix
- 【Linux基础】vim配置及插件安装管理
- Linux下程序的Profile工具