我正在尝试学习makefile,下面是我的模块化项目结构:
$ pwd
/cygdrive/d/Make/Code
$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
|-Build
|-Conversion
|---bin
|-----exe
|-----obj
|---include
|---lib
|---make
|---source
|-Main
|---bin
|-----exe
|-----obj
|---include
|---lib
|---make
|---source
|-Reverse
|---bin
|-----exe
|-----obj
|---include
|---lib
|---make
|---source
三个模块1)转换2)反向3)主要。每个这些模块的makefile
都放在相应的make
文件夹中,他们正确准备相应的.o
文件,并将它们放在各个文件夹的bin/obj
中。
构建目录用于生成.exe
文件,如下所示:
$ cat makefile
all:
cd ../Conversion/make; make
cd ../Reverse/make; make
cd ../Main/make; make
Conversion:
cd ../Conversion/make; make
Reverse:
cd ../Reverse/make; make
Main:
cd ../Main/make; make
exeApp:
cd ../Main/make; make App
cConversion:
cd ../Conversion/make; make clean
cReverse:
cd ../Reverse/make; make clean
cMain:
cd ../Main/make ; make clean
cleanAll:
cd ../Conversion/make; make clean
cd ../Reverse/make; make clean
cd ../Main/make; make clean
和main的makefile
是:
#VPATH= ./../source
INCLUDES= ./../include
OBJDIR= ./../bin/obj
EXEDIR= ./../bin/exe
OBJLOOKDIR= ./../../Conversion/bin/obj:./../../Reverse/bin/obj:./../../Main/bin/obj
#CONBIN= ./../../Conversion/bin/obj
#REVBIN= ./../../Reverse/bin/obj
#MAINBIN= ./../../Main/bin/obj
vpath %.h $(INCLUDES)
vpath %.o $(OBJLOOKDIR)
vpath %.c ./../source
CC= gcc
CFLAGS= -Wall -c -I$(INCLUDES)
OBJECTS= driver.o
PROJECTOBJECTS= binary.o hex.o octal.o reverseNum.o driver.o
main: $(OBJECTS)
driver.o: driver.c conversion.h
$(CC) $(CFLAGS) $< -o $(OBJDIR)/$@
App: $(PROJECTOBJECTS)
$(CC) -Wall $< -o $(EXEDIR)/$@
clean:
rm -rf $(OBJDIR)/*.o *~ $(EXEDIR)/*
但是当我运行make exeApp
时,我得到以下错误:
$ make exeApp
cd ../Main/make; make App
make[1]: Entering directory '/cygdrive/d/Make/Code/Main/make'
gcc -Wall ./../../Conversion/bin/obj/binary.o -o ./../bin/exe/App
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain@16'
collect2: error: ld returned 1 exit status
makefile:26: recipe for target 'App' failed
make[1]: *** [App] Error 1
make[1]: Leaving directory '/cygdrive/d/Make/Code/Main/make'
makefile:17: recipe for target 'exeApp' failed
make: *** [exeApp] Error 2
有些如何不被转换为以下规则:
$ pwd
/cygdrive/d/Make/Code/Main/make
Gaurav@Gaurav-PC /cygdrive/d/Make/Code/Main/make
$ gcc -Wall ./../../Conversion/bin/obj/binary.o ./../../Conversion/bin/obj/hex.o ./../../Conversion/bin/obj/octal.o ./../../Reverse/bin/obj/reverseNum.o ./../../Main/bin/obj/driver.o -o Trial
Gaurav@Gaurav-PC /cygdrive/d/Make/Code/Main/make
$ ls
makefile makefileold Trial.exe
as上述规则编译文件,但exeApp
规则仅转换为gcc -Wall ./../../Conversion/bin/obj/binary.o -o ./../bin/exe/App
。应该是gcc -Wall ./../../Conversion/bin/obj/binary.o ./../../Conversion/bin/obj/hex.o ./../../Conversion/bin/obj/octal.o ./../../Reverse/bin/obj/reverseNum.o ./../../Main/bin/obj/driver.o -o ./../bin/exe/App
我无法找出原因?
任何人都可以帮忙,请。
由于