当前位置: 技术问答>linux和unix
一个关于makefile的写法
来源: 互联网 发布时间:2015-07-06
本文导语: 我的程序中包含10个原码文件(a.cpp/b.cpp/c.cpp/d.cpp......j.cpp),每个文件都要要编译成.o的可执行文件(a.o/b.o/c.o/d.o.....j.o),应该怎么写makefile文件?单个.cpp文件我会写makefile文件,类似这样 CXX = g++ INC = -I/data2/mysql/include/...
我的程序中包含10个原码文件(a.cpp/b.cpp/c.cpp/d.cpp......j.cpp),每个文件都要要编译成.o的可执行文件(a.o/b.o/c.o/d.o.....j.o),应该怎么写makefile文件?单个.cpp文件我会写makefile文件,类似这样
CXX = g++
INC = -I/data2/mysql/include/mysql -I/usr/local/include
-I/usr/local/include/bbstest -I/data0/unipro/include
LIB = -L/data2/mysql/lib/mysql -L/usr/local/lib
-L/usr/local/lib/bbstest
-L/data0/unipro/lib /data0/unipro/lib/c_encrypt.o -lmysqlclient -lwebdev -lflood -lmsgfilter -lcommon -lsocket -lnsl -lresolv
CFLAGS = -Wall -D_REENTRANT -g
all:list_all_vote.cpp vote_def.h
$(CXX) $(CFLAGS) $(INC) -o list_all_vote.cgi list_all_vote.cpp common.cpp $(LIB)
clean:
rm *.cgi
可是多个文件怎么写呢?
CXX = g++
INC = -I/data2/mysql/include/mysql -I/usr/local/include
-I/usr/local/include/bbstest -I/data0/unipro/include
LIB = -L/data2/mysql/lib/mysql -L/usr/local/lib
-L/usr/local/lib/bbstest
-L/data0/unipro/lib /data0/unipro/lib/c_encrypt.o -lmysqlclient -lwebdev -lflood -lmsgfilter -lcommon -lsocket -lnsl -lresolv
CFLAGS = -Wall -D_REENTRANT -g
all:list_all_vote.cpp vote_def.h
$(CXX) $(CFLAGS) $(INC) -o list_all_vote.cgi list_all_vote.cpp common.cpp $(LIB)
clean:
rm *.cgi
可是多个文件怎么写呢?
|
DIRS= yourdir
all:
for i in $(DIRS) ; do (CXX) $(CFLAGS) $(INC) -o list_all_vote.cgi *.cpp $$i || exit $? ; done
all:
for i in $(DIRS) ; do (CXX) $(CFLAGS) $(INC) -o list_all_vote.cgi *.cpp $$i || exit $? ; done
|
objects = a.o b.o c.o d.o.....j.o
all: $(objects)
$(objects): %.o: %.c
$(CC) -c $(CFLAGS) $
all: $(objects)
$(objects): %.o: %.c
$(CC) -c $(CFLAGS) $