我是Stack Overflow的新手。我目前很难解决一个简单的问题。
在我的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 $@ $<
#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 :(得分:1)
问题在于模式规则
%.o: %.c
...
实际上并不符合您要做的事情。源文件实际上是src/shutil.c
,因此此规则不适合。所有Make看到的都是这条规则:
$(OBJS) : $(HEADER_FILES)
没有命令,因此Make得出结论,不需要采取任何措施。然后继续执行simpleshell
的规则,该规则失败,因为对象不存在。
试试这个:
obj/%.o: src/%.c
$(CC) $(CFLAGS) -c -o $@ $<
一旦有了这么多工作,就会有更复杂的变化。
答案 1 :(得分: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`
谢谢你的快速回复!