Unix makefile errors " 'ake: Fatal error: Don't know how to make (c file here)"
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?
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.
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?
As a start, try a makefile which only compiles one thing:
hw2p1_moveit.o: hw2p1_moveit.c
gcc -o moveit.o -c hw2p1_moveit.c
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 :)
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:
OBJS = hw2p1_main.o hw2p1_getit.o hw2p1_parseit.o hw2p1_moveit.o hw2p1_showit.o hw2p1: $(OBJS) $(CC) $(CFLAGS) $(CPPFLAGS) $(OBJS) -o $@
As noted by others--make sure you use an actual tab for the indentation. Make is extremely picky about that.
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.
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!
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/>
'ake: Fatal error: Don't know how to make target
(lastfilename in line)
Hope this helps.
精彩评论