简体   繁体   中英

Makefile, “nothing to be done for all” error

So I have a make file, stored in a directory called "temp" the following directory has a src folder, with 2 .c files "file1.c" and "file2.c". The temp directory also holds a include folder (which is empty), and a bin folder (which is empty until the make command is so posed to be run). I'm currently to trying get a single .c file to compile (get it working),but a single file doesn't even seem to work here.

This is how the directories look:

temp

cd into temp..

bin include Makefile src

Here is my makefile:

all:
    gcc -Wall -pedantic -std=c99 src/file1.c -Iinclude -o bin/runMe -lncurses

And yes, there is a tab before the gcc. Any help on this frustrating issue, would be much appreciated. Also, if possible any input on compiling the second .c file, would also be very helpful!

Nothing to be done for TARGET means that a target has no commands which, in this case, almost certainly means that you do not have a tab on that gcc line.

That being said that's only the immediate problem. This makefile is also not following good practices and will unnecessarily recompile your program (as well as ceasing to work entirely should an all file be created).

DrC had, in a currently deleted answer, very good suggestions for how to improve your makefile to avoid both of those latter issues.

Specically, your makefile should look more like this:

.PHONY: all
all: bin/runMe

bin/runMe: src/file1.c
     gcc -Wall -pedantic -std=c99 $^ -Iinclude -o $@ -lncurses

Which marks the all target as a .PHONY so that an all file or directory getting created won't confuse make as well as setting up a prerequisite on the source file for your built binary so that make can tell when it does (and doesn't) need to rebuild the binary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM