常用的C/C++工程Makefile模板
转帖:一辉的文章
在Linux下做开发难免要接触makefile,整个项目的构建都依赖于它。100个developer有100种makefile的写法,在一个较大的项目中,各种各样的makefile无论在开发、后期维护还是整个系统的持续集成都是一个负担。
有幸参与重构一个遗留系统的makefile,以下是一些心得和一个makefile模板。
重构目的:
1.清晰易懂、容易维护
2.方便系统的持续集成
重构原则:
1.子模块makefile模板化
2.外部依赖、通用宏定义集中化
3.中间和最终输出集中,便于系统构建
下面是总结出的一个makefile模板,我在日常的开发中都用它,其中加入了详细的注释。
view plaincopy to clipboardprint?
#Get the ROOT_PATH which common files located, assuming this makefile located in $(ROOT_PATH)/src/sub_module
ROOT_PATH = $(shell cd ../..; pwd)
#Where define the path of third party modules
include $(ROOT_PATH)/path
#Where define common macros such as CC=gcc, CXX=g++ and so on
include $(ROOT_PATH)/common
#Set target output path and the path of intermidiate object
#The path macros should include in $(ROOT_PATH)/path
OUT_PATH = $(OUTPUT_PATH)/submodule
OBJ_PATH = $(TMPOBJ_PATH)/submodule
TARGET = $(OUT_PATH)/targe
#If the targe is share object then set corresponding flags
#which should define in $(ROOT_PATH)/common
CFLAGS += $(CFLAGS_SO)
LDFLAGS += $(LDFLAGS_SO)
#Custom Predefines
CFLAGS += -DXXXXXXXX
CFLAGS += -DYYYYYYYY
#Dependent header files
#The path macros should include in $(ROOT_PATH)/path
CFLAGS += -I. \
-I$(XXXX_INC) \
-I$(YYYY_INC) \
-I$(ZZZZ_INC)
#Dependent libraries
#The path macros should include in $(ROOT_PATH)/path
LDFLAGS += -L$(XXXX_LIB) -lxxxx \
-L$(YYYY_LIB) -lyyyy
#Set CPP source directory
CPP_SRCDIR = .
#Or set specific CPP Source files
ADDITIONAL_CPP_SOURCES = \
$(PATH_A)/a.cpp \
$(PATH_B)/b.cpp
#Traverse every directory in $(CPP_SRCDIR), and find every cpp file
CPP_SOURCES = $(foreach d,$(CPP_SRCDIR),$(wildcard $(d)/*.cpp) ) $(ADDITIONAL_CPP_SOURCES)
#Traverse every cpp file in $(CPP_SOURCES) and get corresponding object file(.
相关文档:
楔子
去年,周星星大哥曾经在VCKBASE/C++论坛发表过一篇文章“数组引用"以避免"数组降阶”,当时我不能深入理解这种用法的含义;时隔一年,我的知识有几经锤炼,终于对此文章渐有所悟,所以把吾所知作想具体道来,竟也成了一篇文章。希望本文能对新手有所启迪,同时也希望大家发现本文中的疏漏之处后不吝留 ......
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<linux/config.h>
#include<linux/module.h>
#include<linux/version.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/errno.h>
#include<linux/sche ......
----------------------------------------------------------------------------------------------------------------------------------------
/**/
/*
********************************************************************************************************
* @Description:s3c2410的rtc驱动的实 ......
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include ".\sqlite3_lib\sqlite3.h"
static int _callback_exec(void * notused,int argc, char ** argv, char ** aszColName)
{
int i;
for ( i=0; i<argc; i++ )
......
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......