如何修复在Dev C和Netbeans中工作的makefile,而不是在Eclipse中?

时间:2023-01-13 11:27:16

Alright, this is for a school project where I am supposed to complete a skeleton program provided by the professor. Here is the makefile as provided to me:

好的,这是一个学校项目,我应该完成教授提供的一个框架程序。这里是提供给我的makefile:

db: db.o students.o courses.o enrolls.o
    cc db.o students.o courses.o enrolls.o -o db
db.o: db.c types.h students.h courses.h enrolls.h db.h
    cc -c db.c
students.o: students.c types.h students.h
    cc -c students.c
courses.o: courses.c types.h courses.h
    cc -c courses.c
enrolls.o: enrolls.c types.h students.h courses.h enrolls.h
    cc -c enrolls.c

Now, this worked fine in the commandline (with gcc) and in Dev C++, but when I tried to use Netbeans it threw an error, saying something about the clean command. So, I added this line:

现在,这在命令行(与gcc一起)和Dev c++中都运行得很好,但是当我尝试使用Netbeans时,它抛出了一个错误,说了一些关于clean命令的事情。我加上了这一行

clean:
    rm -f *.exe *.o

to the end of the file, and it worked fine (in Netbeans). But, it still won't work in Eclipse CDT. It gives this error:

在文件的末尾,它工作得很好(在Netbeans中)。但是,它在Eclipse CDT中仍然不起作用。它让这个错误:

Description Resource    Path    Location    Type
make: *** No rule to make target `all'.  Stop.  Course Project          C/C++ Problem

So, I tried adding

所以,我试着增加

all:db

to the top, but then it throws this error:

到顶部,然后它抛出这个错误:

Description Resource    Path    Location    Type
make: *** [db] Error 1  Course Project          C/C++ Problem

So, now I'm at a loss for what to do. I've Googled around, but nothing has seemed to work yet. Any ideas on how to change this makefile so it works in Eclipse?

所以,现在我不知所措。我用谷歌搜索了一下,但似乎什么都没有。关于如何更改这个makefile的任何想法,使它在Eclipse中工作?

Here is the makefile in its current (non-functional) form:

下面是makefile的当前(非功能)形式:

all:db

db: db.o students.o courses.o enrolls.o
    cc db.o students.o courses.o enrolls.o -o db
db.o: db.c types.h students.h courses.h enrolls.h db.h
    cc -c db.c
students.o: students.c types.h students.h
    cc -c students.c
courses.o: courses.c types.h courses.h
    cc -c courses.c
enrolls.o: enrolls.c types.h students.h courses.h enrolls.h
    cc -c enrolls.c
clean:
    rm -f *.exe *.o

1 个解决方案

#1


1  

As far as I know, Eclipse use gnu make/gcc as a default build toolchain. So if your makefile works in a shell it should work in Eclipse. The first error you mention just points out that Eclipse build with the default command "make all". Adding 'all: db' should have corrected this problem. As @Bug Catcher said you should have a space between 'all:' and 'db'. You can also add a .PHONY statement :

据我所知,Eclipse使用gnu make/gcc作为默认的构建工具链。因此,如果makefile在shell中工作,那么它应该在Eclipse中工作。您提到的第一个错误指出,使用默认命令“make all”构建Eclipse。添加“all: db”应该已经纠正了这个问题。正如@Bug捕捉者所说,你应该在“所有”和“db”之间有一个空格。您还可以添加.PHONY语句:

.PHONY: all db clean

all: db
    @echo "Done !"

# [...]

#1


1  

As far as I know, Eclipse use gnu make/gcc as a default build toolchain. So if your makefile works in a shell it should work in Eclipse. The first error you mention just points out that Eclipse build with the default command "make all". Adding 'all: db' should have corrected this problem. As @Bug Catcher said you should have a space between 'all:' and 'db'. You can also add a .PHONY statement :

据我所知,Eclipse使用gnu make/gcc作为默认的构建工具链。因此,如果makefile在shell中工作,那么它应该在Eclipse中工作。您提到的第一个错误指出,使用默认命令“make all”构建Eclipse。添加“all: db”应该已经纠正了这个问题。正如@Bug捕捉者所说,你应该在“所有”和“db”之间有一个空格。您还可以添加.PHONY语句:

.PHONY: all db clean

all: db
    @echo "Done !"

# [...]