linker input file unused because linking not done - gcc

半世苍凉 提交于 2021-01-28 01:38:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!