Unix makefile 错误” “ake:致命错误:不知道如何制作(此处为 c 文件)”
我编写了以下 makefile:
hw2p1: hw2p1_main.o hw2p1_getit.o hw2p1_parseit.o hw2p1_moveit.o hw2p1_showit.o
gcc hw2p1_main.o hw2p1_getit.o hw2p1_parseit.o hw2p1_moveit.o hw2p1_showit.o
hw2p1_main.o: hw2p1_main.c
gcc -c hw2p1_main.c
hw2p1_getit.o: hw2p1_getit.c
gcc -c hw2p1_getit.c
hw2p1_parseit.o: hw2p1_parseit.c
gcc -c hw2p1_parseit.c
hw2p1_moveit.o: hw2p1_moveit.c
gcc -c hw2p1_moveit.c
hw2p1_showit.o: hw2p1_showit.c
gcc -c hw2p1_showit.c
第一次尝试调用 make 时,收到错误:“make:致命错误:意外的行结束” 我删除了目标之间的空白行并再次调用 make,但这一次我得到“ 'ake:致命错误:不知道如何制作 hw2p1_main.c”
我已经分别编译了所有这些文件,然后链接了它们,所以我知道这些错误是由于不正确的 makefile 而不是由于我的 c 文件中出现错误。
这是我写的第一个 makefile,所以我可能完全错误地完成了它。不管怎样,关于如何消除这些错误有什么建议吗?
I've written the below makefile:
hw2p1: hw2p1_main.o hw2p1_getit.o hw2p1_parseit.o hw2p1_moveit.o hw2p1_showit.o
gcc hw2p1_main.o hw2p1_getit.o hw2p1_parseit.o hw2p1_moveit.o hw2p1_showit.o
hw2p1_main.o: hw2p1_main.c
gcc -c hw2p1_main.c
hw2p1_getit.o: hw2p1_getit.c
gcc -c hw2p1_getit.c
hw2p1_parseit.o: hw2p1_parseit.c
gcc -c hw2p1_parseit.c
hw2p1_moveit.o: hw2p1_moveit.c
gcc -c hw2p1_moveit.c
hw2p1_showit.o: hw2p1_showit.c
gcc -c hw2p1_showit.c
The first time I tried to call make, I got the error: "make: Fatal error: unexpected end of line seen" I deleted the blank lines between targets and called make again, but this time I got " 'ake: Fatal error: Don't know how to make hw2p1_main.c"
I've compiled all of these files separately and then linked them so I know that the errors are a result of an incorrect makefile and not a result of errors in my c files.
This is the first makefile that I've ever written so I might just be doing it completely incorrectly. Either way, any suggestions on how to get rid of these errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
当目录无意中不是应有的目录时,就会发生这种情况,因此看起来
hw2p1_main.c
的缺失需要规则来创建 C 源文件。也可能是文件名拼写错误。
This can happen when the directory is inadvertently not the one it should be so it looks like
hw2p1_main.c
's absence calls for a rule to create the C source file.It could also be a filename misspelling.
您似乎在链接命令中缺少 -o,尽管您可能还没有想到这一点。直接的抱怨是 make 找不到该 .c 文件。确定它在当前工作目录中吗?
You seem to be missing the -o in the linking command, though that's probably not what's on your mind yet. The immediate complaint is that make can't find that .c file. Sure it's there in the current working directory?
首先,尝试一个只编译一件事的 makefile:
另外,确保第二行使用制表符,而不是空格。 (我必须在编辑器中手动设置它,因为空格是唯一明智的方法:)
As a start, try a makefile which only compiles one thing:
Also, make sure that the 2nd line uses a TAB character, rather than spaces. (I have to manually set this in my editor because spaces are the only smart way to do it :)
你的 Makefile 比它需要的要复杂得多。让 Make 使用它的隐式规则。它知道如何从 foo.c 生成 foo.o,而您不需要告诉它。您的整个 Makefile 可以简化为:
正如其他人所指出的 - 确保您使用实际的制表符进行缩进。 Make对此非常挑剔。
Your Makefile is way more complicated than it needs to be. Let Make use its implicit rules. It knows how to make foo.o from foo.c, and you don't need to tell it that. Your entire Makefile can be reduced to:
As noted by others--make sure you use an actual tab for the indentation. Make is extremely picky about that.
只是在黑暗中刺探,但文件名的大小写是否匹配?来自 Windows/Apple 世界的一些人对 UNIX 文件名区分大小写感到惊讶。
您可以通过从错误输出中准确复制文件名并尝试列出它来检查这一点,即
ls -l <paste>
。这还应该显示文件名中是否嵌入了一些控制字符,这也可能是您的问题。Just a stab in the dark, but does the filename's case match? Coming from a windows/apple world, some people are surprised that unix filenames are case sensitive.
You can check this by copying the filename exactly from the error output and trying to list it, i.e.
ls -l <paste>
. That should also show you whether there's some control characters embedded in the filename, which could also be your problem.这个答案几乎永远不可能得到!好的,基本上我找到了解决方案。你写的makefile是健全的。但是,您必须在 EMACS 中创建它。很奇怪吧?我有一个提交到期,并在记事本中编写了我的 makefile 并将其上传到大学服务器上,但它从未运行!我尝试使用不同的代码变体,但没有成功。然后,我沮丧地在 EMACS 中重新输入了整个内容,结果就成功了。无需修改代码。试一试吧!
This answer is almost never available! Okay, so basically I found a solution. The makefile you've written is sound. However, you have to create it in EMACS. Wierd right? I had a submission due and had written my makefile in notepad and uploaded it onto the university server, and it never ran! I tried using different variants of the code to no luck. Then in frustration I retyped the whole thing in EMACS, and it just worked. No modifications to the code. Give it a shot!
如果您已确定
1) 它所说的丢失的所有文件都与 makefile 位于同一目录中,或者按照指示的路径
2) 所有命令行都包含制表符而不是空格(最简单的检查方法是按向左箭头键在第一个字符处,它应该返回到起始位置(行位置的第 0 个字符)
然后大多数时候问题是 Makefile 的文件格式
如果您在具有 PC (CR/LF) 行格式的编辑器中键入文件,则必须将其设置为仅 CR 文件格式。
因此,您可以在 vi 或 emacs 或任何其他具有 UNIX 默认文件格式的编辑器中键入 Makefile,它将起作用,或者在您的编辑器中将文档文件格式设置为 UNIX 类型(如果它允许设置)。
这必须适用于所有类型的错误
'ake:致命错误:不知道如何使目标
(或)
(行中的最后一个文件名)>
'ake:致命错误:不知道如何创建目标
希望这有帮助。
If you have made sure
1) That all files it's saying are missing are in same directory as that of makefile or otherwise as per path indicated
2) all command lines are containing tabs and not spaces (easiest way to check is to press a left arrow key at your first character and it should return to home position (0th char of line position)
Then Most of the time the problem is file format of Makefile
If you are typing a file in an editor having a PC (CR/LF) Line format then you will have to set it to just CR file format.
So, you can type the Makefile in vi or emacs or any other editor which has default file format of UNIX and it will work or set your document file format to be of UNIX type in your editor if it allows to set one.
This must work for all errors of type
'ake: Fatal error: Don't know how to make target
(OR) <BR/>
(lastfilename in line)'ake: Fatal error: Don't know how to make target
Hope this helps.