2011-10-06 46 views
2

我有內容的很小make文件VPATH在makefile

VPATH = src 

main: main.o 
     gcc -o main main.o 

main.o: main.c 
     gcc -c main.c 

當前目錄包含其中包含的main.c

當我執行令,我得到錯誤src目錄不wotking

gcc -c main.c 
gcc: main.c: No such file or directory 
gcc: no input files 
make: *** [main.o] Error 1 

當我在當前目錄中移動main.c時,它工作。看來VPATH宏不起作用。請讓我知道VPATH的用法。

回答

6

雖然make位於main.c就好了,你在這裏失去了使用自動變量:

main.o : main.c 
     gcc -o [email protected] -c $< 

將由擴大做出了gcc呼叫

gcc -o main.o -c src/main.c 

始終使用automatic variables$<(第一先決條件)和[email protected](目標),你可以使它們變得更強大,更易於閱讀。