c make 文件,如何制作一个可以编译四个源文件的文件?

发布于 2025-01-01 09:49:11 字数 911 浏览 0 评论 0 原文

这是我的作业。我正在寻求有关如何制作将编译三个源文件的“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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2025-01-08 09:49:11

(顺便说一句,如果您手动运行 cl timestable.c tablein.c tableout.c timestable.h 会发生什么?)

您通常需要编写 Makefile 来编译使用 模式规则知道如何将单个 .c 文件编译为 .obj 文件,然后另一个规则知道如何链接所有 .obj 文件合并为一个可执行对象。 (一个重要的好处是,这允许仅重建已更改的部分。到目前为止,您的 Makefile 将需要在任何一个更改时重新编译所有输入文件。)

当您有这么多 .obj 时 文件放置在周围,您可能需要一个 make clean 来删除所有可以从源重建的目标文件和可执行文件。这可能很简单,只需将 clean 声明为虚假目标,然后删除所有可以重建的文件即可。

请注意,Makefile 按照惯例命名为 MakefilemakefileGNUmakefile。 (GNU make 实际上按照此列表的相反顺序搜索文件,但 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. Your Makefile 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 a make clean that removes all the object files and executable files that can be rebuilt from sources. That might be as simple as declaring clean to be a phony target and then deleting all the files that can be rebuilt.

Note that Makefiles are by convention named Makefile or makefile or GNUmakefile. (GNU make actually searches for the files in the reverse order to this list, but Makefile is the only name I like.) If you use one of these names, then you can just run make foo to run the foo 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.)

最近可好 2025-01-08 09:49:11

当然,您的老师/学校提供了一些课程笔记,其中解释了 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, or nmake 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 for make 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? ;) ).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文