C++ Makefile 问题:g++:致命错误:没有输入文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21653680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:45:17  来源:igfitidea点击:

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

c++makefilefile-not-found

提问by NewGradDev

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.

我已经查看了其他具有类似问题的 StackOverflow 线程,但它们似乎都不适用于我的特定情况。我还仔细检查以确保正确的文件位于正确的位置(文件夹),并且所有内容的命名也正确。

This is the error I'm receiving:

这是我收到的错误:

[[email protected]]$ 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:

这是有问题的makefile:

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:

以下是 makefile 引用的文件(它们都在同一目录中):

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

What am I doing wrong?

我究竟做错了什么?

回答by Diego R. Alcantara

Try doing

尝试做

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

Compiledfilename is the name of the binary file.

Compiledfilename 是二进制文件的名称。

回答by smani

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

回答by user2472134

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 .hfile with .hppfile. It worked :)

我知道现在回答已经太晚了。但这可能对其他人有所帮助。我遇到过同样的问题。我通过用.hpp文件替换.h文件来修复它。有效 :)