gcc make file demo

本文详细介绍了一个实际项目的Makefile文件配置,包括编译器的选择、编译选项、源文件与目标文件的定义,以及具体的编译规则等核心内容。通过本文,读者可以了解如何设置Makefile以实现项目的自动化构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

##
## sample makefile, written by Jeff Juliano for COMP 121L class on Sept 10
##
## The '#' character at the beginning of a line means that the line is a
## comment.  I use a double '##' to denote editorial comments,
## and a single '#' to mark "code" that I have temporarily commented out.
##
## a makefile should be in the same directory as your project.  It
## should be named either "Makefile" or "makefile".  The capitalize
## version is better, because make will use that one if both versions exist.


## the next 2 lines specify the compiler and the compiler switches
## the compiler switch -g tells the compiler to compile in a 
##     way that a debuGger will understand the program
## the -Wall switch turns on all warnings (you should ALWAYS do this)
## the -ffor-scope switch fixes a bug in the current version of g++
## if you don't use g++, get rid of -Wall and -ffor-scope
CXX = g++
CXXFLAGS = -g -Wall -ffor-scope

## create a variable containing the names of all the .C files
SRCS = array.C string.C string.array.C menu.C demo.C

## create a variable containing the names of all the .o files
## compute the value from SRCS
OBJS = $(SRCS:.C=.o)


######################### rules follow ##################################

## this will link all the files and call the executable "demo"
## Note: the link rule must be the first rule in the makefile
demo: $(OBJS)
	g++ -o $@ $(OBJS)


## the following is a list of dependencies
## NOTE: there are no compilation rules given, do the default will be used
array.o: array.C array.h
string.o: string.C string.h
string.array.o: string.array.C string.array.h array.h string.h
menu.o: menu.C menu.h
demo.o: demo.C string.array.h menu.h


## Default rule for compiling all .C files without an explicit rule
## You can override the default by simply providing an explicit one
## This is read "to go to a .o from a .C, do the following rule"
##
## as before, a -c flag is needed to tell it to compile and not link
## $< expands to the name of the first file to the right of the colon
## $@ expands to the name to the left of the colon
%.o : %.C
	$(CXX) $(CXXFLAGS) -c $< -o $@


## this rule will remove the executable and all the .o files
## note that there are no dependencies
clean:
	/bin/rm -f $(OBJS) demo
 
原文链接:http://www.unc.edu/~mserre/mfEx/mf3

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值