这是我的作业。我正在寻求有关如何制作将编译三个源文件的“makefile”的帮助。其中将被命名为“timestable.c tablein.c tableout.c timestable.h”。这是四个源文件。我创建了一个 makefile 来执行此操作,我认为这是正确的,但我不确定如何测试它以查看它是否可以编译?这是我的 makefile 的内容:
timestable.exe: timestable.c tablein.c tableout.c timestable.h
cl timestable.c tablein.c tableout.c timestable.h
这是正确的吗?此 makefile 必须使用 Visual Studio cl 命令构建一个名为 timestable.exe 的程序,并提供 clean 功能。当老师提到“clean”功能时,我不明白老师在说什么。我不确定这个 makefile 是否真的可以创建这个文件,因为我不确定如何运行它。
另外,如果你们不介意给我一个链接或告诉我一些有关基于 Windows 的系统的 makefile 命令的更多信息。我希望在我的 makefile 中创建“额外功能”,因为这样做会给我更好的分数,但我不知道我还能做什么。
提前致谢。
大编辑:
因此,经过一番尝试后,我发现如果我将 makefile.txt 文件更改为 makefile.bat 并打开 Visual Studio cmd 提示符,进入正确的目录并输入(我知道我没有运行 cmd promt 以运行 .bat 文件):
makefile.bat
它将尝试编译所有文件。问题是它不适用于“.h”文件,特别是 timestable.h 文件。此外,“timestable.exe”命令不起作用。知道在这里做什么吗?
This is my homework. I'm looking for help on how to a make a "makefile" that will compile three source files. Of which will be named "timestable.c tablein.c tableout.c timestable.h". Those are the four source files. I have created a makefile to do this, which I believe is correct, but I'm not sure how to test it to see if it will compile? Here is the content of my makefile:
timestable.exe: timestable.c tablein.c tableout.c timestable.h
cl timestable.c tablein.c tableout.c timestable.h
Is this correct? This makefile has to build a program called timestable.exe using the Visual Studio cl command and to provide the clean functionality. I don't understand what I am being told when the teacher mentioned the "clean" functionality. I'm not sure if this makefile actually works to create this file, because I'm not sure how to run it.
Also, if you guys don't mind giving me a link or telling me some more info on makefile commands for a windows based system. I wish to create and "extra feature" in my makefile because doing so will grant me better marks, and I do not know what more I could do.
Thanks ahead of time.
BIG EDIT:
So, after playing around a bit, I figured out that if I change the makefile.txt file to makefile.bat and I open my visual studio cmd prompt, get into the correct directory and type in (I'm aware I do not have to run the cmd promt in order to run the .bat file) :
makefile.bat
it will attempt to compile all the files. The issue, is it does not work with the ".h" file, specifitcly the timestable.h file. Also, the "timestable.exe" command didn't work. Any idea on what to do here?
发布评论
评论(2)
(顺便说一句,如果您手动运行
cl timestable.c tablein.c tableout.c timestable.h
会发生什么?)您通常需要编写
Makefile
来编译使用 模式规则知道如何将单个.c
文件编译为.obj
文件,然后另一个规则知道如何链接所有.obj
文件合并为一个可执行对象。 (一个重要的好处是,这允许仅重建已更改的部分。到目前为止,您的Makefile
将需要在任何一个更改时重新编译所有输入文件。)当您有这么多
.obj 时
文件放置在周围,您可能需要一个make clean
来删除所有可以从源重建的目标文件和可执行文件。这可能很简单,只需将clean
声明为虚假目标,然后删除所有可以重建的文件即可。请注意,Makefile 按照惯例命名为
Makefile
或makefile
或GNUmakefile
。 (GNUmake
实际上按照此列表的相反顺序搜索文件,但Makefile
是我唯一喜欢的名称。)如果您使用这些名称之一,那么您只需运行make foo
即可运行foo
目标。如果您为 Makefile 选择不同的名称,那么您还需要使用 -f filename 命令行选项来选择其他文件,这很烦人。有时是必要的。)(Incidentally, what happens if you run
cl timestable.c tablein.c tableout.c timestable.h
by hand?)You'd normally want to write your
Makefile
to compile your.c
files to.obj
files using pattern rules that know how to compile a single.c
file into an.obj
file and then another rule that knows how to link all the.obj
files into a single executable object. (One important benefit is that this allows rebuilding only the parts that have changed. YourMakefile
so far will require recompiling all inputs file any time any one changes.)When you have so many
.obj
files laying around, you might want amake clean
that removes all the object files and executable files that can be rebuilt from sources. That might be as simple as declaringclean
to be a phony target and then deleting all the files that can be rebuilt.Note that Makefiles are by convention named
Makefile
ormakefile
orGNUmakefile
. (GNUmake
actually searches for the files in the reverse order to this list, butMakefile
is the only name I like.) If you use one of these names, then you can just runmake foo
to run thefoo
target. If you pick a different name for your Makefile then you also need to use the-f filename
command line option to pick the other file, and that is annoying. Sometimes necessary.)当然,您的老师/学校提供了一些课程笔记,其中解释了
make
/nmake
的基础知识,如果他们希望您将其用于作业;或者至少有一些在线材料的指示?您似乎对 makefile 到底是什么以及如何使用它感到困惑。您不需要像批处理脚本那样直接从命令行运行它,而是需要一个程序(称为
make
,如果您使用的是 Visual Studio,则称为nmake
); makefile 是一种由该程序读取的输入脚本。然后,程序使用 makefile 中的信息来确定需要运行哪些命令来更新主目标。您应该能够找到一些比我在这里更好地描述
make
基础知识的教程。在 Google 上快速搜索make 教程
得到了以下链接:http ://www.eng.hawaii.edu/Tutor/Make/。我浏览了一下,似乎是一个不错的介绍(它使用了图片和简短的部分,所以它一定很好,对吧?;))。
Surely your teacher/school provided some course notes, where the basics of
make
/nmake
are explained, if they expect you to use it for your homework; or at the very least some pointers to online material?You seem to be confused about what exactly a makefile is, and how you use it. You don't directly run it from the commandline like a batch script, but you need a program (called
make
, ornmake
if you're using Visual Studio); the makefile is a sort of input script which is read by that program. The program then uses the info in the makefile to determine what commands it needs to run to update the main target.You should be able to find some tutorials that describe the basics of
make
much better than I can do here. A quick search on Google formake tutorial
came up with this link: http://www.eng.hawaii.edu/Tutor/Make/ .I glanced through it and it seems like a nice introduction (it uses pictures and short sections, so it must be good, right? ;) ).