2013-10-16 153 views
2

我是Stack Overflow的新手。我目前很難解決一個簡單的問題。Makefile錯誤信息

在我shell/目錄中,我有:

CVS/ 
include/ 
Makefile 
obj 
src 

試圖直接目標文件時,要建在obj,但會出現我的問題,當我運行make用下面的代碼:

# Beginning of Makefile 
OBJS = obj/shutil.o obj/parser.o obj/sshell.o 
HEADER_FILES = include/shell.h include/parser.h 
EXECUTABLE = simpleshell 
CFLAGS = -Wall 
CC = gcc 
# End of configuration options 

#What needs to be built to make all files and dependencies 
all: $(EXECUTABLE) 

#Create the main executable 
$(EXECUTABLE): $(OBJS) 
     $(CC) -o $(EXECUTABLE) $(OBJS) 

#Recursively build object files 
%.o: %.c 
     $(CC) $(CFLAGS) -c -o [email protected] $< 

#Define dependencies for objects based on header files 
#We are overly conservative here, parser.o should depend on parser.h only 
$(OBJS) : $(HEADER_FILES) 

clean: 
     -rm -f $(EXECUTABLE) obj/*.o 
run: $(EXECUTABLE) 
     ./$(EXECUTABLE) 

tarball: 
     -rm -f $(EXECUTABLE) obj/*.o 
     (cd .. ; tar czf Kevin_Fairchild_a3.tar.z shell) 

# End of Makefile 

我收到此錯誤:

gcc -o simpleshell obj/shutil.o obj/parser.o obj/sshell.o 
gcc: obj/shutil.o: No such file or directory 
gcc: obj/parser.o: No such file or directory 
gcc: obj/sshell.o: No such file or directory 
gcc: no input files 
make: *** [simpleshell] Error 1 

我錯過了什麼簡單的片段?我將繼續研究和了解的Makefile

+0

你認爲是什麼問題? – ouah

+0

不太確定,請看看我的答案。 –

回答

1

麻煩的是,該模式規則

%.o: %.c 
    ... 

實際上並不符合你想要做什麼。源文件實際上是src/shutil.c,所以這個規則不適合。所有Make看到的是這個規則:

$(OBJS) : $(HEADER_FILES) 

沒有命令,所以請做出結論,沒有必要的行動。然後它繼續執行simpleshell的規則,該規則因爲對象不在那裏而失敗。

試試這個:

obj/%.o: src/%.c 
    $(CC) $(CFLAGS) -c -o [email protected] $< 

有更復雜的變化,一旦這麼多的工作。

+0

我在發佈之前最初做了修改,但請看看我的答案。 –

0

補充說,簡單的修改,這是我在這裏發帖之前最初嘗試,即

obj/%.o: src/%.c 

我收到這個錯誤,所以原本我後雖然是別的東西。

gcc -Wall -c -o obj/shutil.o 
src/shutil.c 
src/shutil.c:14:19: error: shell.h: No such file or directory 
src/shutil.c: In function ‘signal_c_init’: 
src/shutil.c:72: error: ‘waitchildren’ undeclared (first use in this function) 
src/shutil.c:72: error: (Each undeclared identifier is reported only once 
src/shutil.c:72: error: for each function it appears in.) 
src/shutil.c: In function ‘checkbackground’: 
src/shutil.c:90: warning: implicit declaration of function ‘striptrailingchar’ 
src/shutil.c: At top level: 
src/shutil.c:101: warning: conflicting types for ‘striptrailingchar’ 
src/shutil.c:90: note: previous implicit declaration of ‘striptrailingchar’ was here 
make: *** [obj/shutil.o] Error 1` 

感謝您的快速回復!

+0

你只是忘了指定包含gcc的dir路徑:使用$(CC)-o $(EXECUTABLE)$(OBJS)-Ilude – pmod