2013-10-16 154 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