在终端中运行make命令时发生g++编译错误(致命错误)



我在windows 10中安装了visual studio代码。我想运行我的c++程序。我有一个简单的文件:hello.cpp。我创建了一个制作文件

这是我的c++文件:hello.cpp

#include<iostream>
using namespace std;
int main(){
cout<<"Hello world "<<std::endl;
return 0;
}

生成文件

# Compiler settings - Can be customized.
CC = g++
CXXFLAGS = -std=c++11 -Wall
LDFLAGS = 
# Makefile settings - Can be customized.
APPNAME = testing
EXT = .cpp
SRCDIR = /d/courseera/courses/testing
OBJDIR = obj
############## Do not change anything from here downwards! #############
SRC = $(wildcard $(SRCDIR)/*$(EXT))
OBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)/%.o)
DEP = $(OBJ:$(OBJDIR)/%.o=%.d)
# UNIX-based OS variables & settings
RM = rm
DELOBJ = $(OBJ)
# Windows OS variables & settings
DEL = del
EXE = .exe
WDELOBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)\%.o)
######################################################################## 
####################### Targets beginning here #########################
########################################################################
all: $(APPNAME)
# Builds the app
$(APPNAME): $(OBJ)
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
# Creates the dependecy rules
%.d: $(SRCDIR)/%$(EXT)
@$(CPP) $(CFLAGS) $< -MM -MT $(@:%.d=$(OBJDIR)/%.o) >$@
# Includes all .h files
-include $(DEP)

# Building rule for .o files and its .c/.cpp in combination with all .h
$(OBJDIR)/%.o: $(SRCDIR)/%$(EXT)
$(CC) $(CXXFLAGS) -o $@ -c $<

################### Cleaning rules for Unix-based OS ###################
# Cleans complete project
.PHONY: clean
clean:
$(RM) $(DELOBJ) $(DEP) $(APPNAME)
# Cleans only all files with the extension .d
.PHONY: cleandep
cleandep:
$(RM) $(DEP)
#################### Cleaning rules for Windows OS #####################
# Cleans complete project
.PHONY: cleanw
cleanw:
$(DEL) $(WDELOBJ) $(DEP) $(APPNAME)$(EXE)
# Cleans only all files with the extension .d
.PHONY: cleandepw
cleandepw:
$(DEL) $(DEP)

当我在终端中发出make命令时,我会收到这样的错误:

g++ -std=c++11 -Wall -o testing  
g++: fatal error: no input files
compilation terminated.
Makefile:36: recipe for target 'testing' failed
make: *** [testing] Error 1

有人能帮我解决这个错误吗?(提示:我的文件hello.cpp在测试的文件夹中(

我将解释其他评论者的观点:在给定所显示的makefile的情况下,获得此处所见输出的唯一方法是OBJ变量为空。OBJ为空的唯一方法是如果SRC为空。SRC为空的唯一方法是wildcard函数扩展为空字符串。wildcard可以扩展到空字符串的唯一方法是,如果它与任何内容都不匹配。所以,问题是为什么通配符函数与任何内容都不匹配?

有两种可能性。第一个是你打错了路径,这只是一个打字错误。

第二个是,你似乎在使用Windows,在Windows上一切都很困难和烦人。特别是,Windows上有多种不同的环境:有一种cygwin风格的环境,其中类似POSIX的路径被映射到类似Windows的路径(例如,/d/foo/bar被映射到D:foobar(。有一个MinGW风格的环境,其中使用了Windows风格的路径,但为了简化操作,可以使用正斜杠而不是反斜杠。然后是完整的Windows cmd.com环境,您必须在其中使用反斜杠。其中不同的需要在不同的地方使用。

GNU make在Windows上有两种版本:cygwin版本和MinGW/VisionStudio版本。如果您有cygwin版本,则需要使用类似POSIX的路径。如果你有MinGW/VisionStudio版本,你需要使用Windows路径,但要使用正斜杠而不是反斜杠。所以,如果你有GNU的MinGW/VisionStudio版本,你应该写:

SRCDIR = D:/courseera/courses/testing

(假设这是正确的路径(。

最新更新