问题
I am a beginner in writing makefiles. I have a makefile something like this:
PATH1 = /ref
CC=gcc
LINK = gcc
INCLUDES = .
INCLUDES += -I/PATH1/inc \
-I/$(PATH1)/abc/inc/ \
-I/$(PATH1)/def/inc/
all: src_file
run: src_file
src_file:
$(CC) $(INCLUDES) -MM /ref/abcd.c -o $@
clean:
rm -f *.o src_file
If I do a make, I get the error:
linker input file unused because linking not done.
I read some similar posts in stackoverflow but couldn't get a solution. Could anybody please let me know what's wrong with my makefile? Thanks in advance.
回答1:
The culprit is the preprocessor option -MM. From gcc pre-processor options,
-M
Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.
Passing -M to the driver implies -E, and suppresses warnings with an implicit -w.
-MM
Like -M but do not mention header files that are found in system header directories, nor header files that are included, directly or indirectly, from such a header.
So effectively you are just preprocessing and hence no compilation and no linking and the resultant error.
来源:https://stackoverflow.com/questions/10486698/linker-input-file-unused-because-linking-not-done-gcc