C++ Makefile 模版

三月 16, 2007 @ 5:26 上午 | 发表在 C/C++ | 留下评论

偶尔需要做些C++的项目,第一件事情就是写Makefile.其实我需要的Makefile都是大同小异.但每次都要花些时间重新写一个.终于决定把模板记下来.
目录结构:
[项目根目录]

| — inc
| — src
| — bin

头文件位于inc, .cpp位于src,生成的可执行文件位于bin. 这个Makefile也是位于src下面.

每添加一个新文件的时候,只需要在OBJS里面加上对应的项就可以.

# Compiler options
CC = g++
DEBUG = -g
CFLAGS = -Wall -c $(DEBUG)
LFLAGS = -Wall $(DEBUG)# Project layout
INC_DIR = ../inc
BIN_DIR = ../bin
EXE = licenseAgent
OBJS = LicenseAgent.o License.o Log.o
INCLUDES = -I $(INC_DIR)

all:$(EXE)

$(EXE): $(OBJS)
\mkdir -p $(BIN_DIR)
$(CC) $(LFLAGS) -o $(BIN_DIR)/$(EXE) $(OBJS)

clean:
\rm $(BIN_DIR)/$(EXE) $(OBJS)

%.o: %.C
$(CC) $(CFLAGS) $(INCLUDES) -c $<

Advertisements

发表评论 »

RSS feed for comments on this post. TrackBack URI

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

通过访问 WordPress.com 创建免费网站或博客.
Entries评论 feeds.

%d 博主赞过: