Makefile issues: g++: fatal error: no input files

可紊 提交于 2019-12-20 04:13:12

问题


What I've already done:

I've looked through other StackOverflow threads with similar issues, but none of them seem to apply to my specific case. I've also double checked to makes sure that the correct files are in the correct locations (folders) and that everything is named properly as well.

This is the error I'm receiving:

[employee_xyz@petco.com]$ make
g++ -Wall -O2 -ansi -pedantic -o dog.cpp
g++: fatal error: no input files
compilation terminated.
make: *** [mscp.o] Error 4

Here's the makefile in question:

CC = g++
CFLAGS = -Wall -O2 -ansi -pedantic -Werror

TARGETS = dog dog.o collar.o

dog: dog.o collar.o
    $(CC) $(CFLAGS) -o dog collar.o dog.o

dog.o: dog.cpp collar.h
    $(CC) $(CFLAGS) -o dog.cpp

collar.o: collar.cpp collar.h
    $(CC) $(CFLAGS) -o collar.cpp

clean:
    -rm -f ${TARGETS}

Here are the files (they're all in the same directory) that are being referenced by the makefile:

-collar.cpp
-collar.h
-makefile
-dog.cpp

What am I doing wrong?


回答1:


This

dog.o: dog.cpp collar.h
    $(CC) $(CFLAGS) -o dog.cpp

collar.o: collar.cpp collar.h
   $(CC) $(CFLAGS) -o collar.cpp

should read

dog.o: dog.cpp collar.h
    $(CC) $(CFLAGS) -c dog.cpp

collar.o: collar.cpp collar.h
    $(CC) $(CFLAGS) -c collar.cpp



回答2:


Try doing

   $(CC) $(CFLAGS) - c collar.cpp -o compiledfilename

Compiledfilename is the name of the binary file.




回答3:


I know it is too late to answer. But this might help some else. I had the same issue. And I fixed it by replacing .h file with .hpp file. It worked :)



来源:https://stackoverflow.com/questions/21653680/makefile-issues-g-fatal-error-no-input-files

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