Visual studio code 如何使Linux Makefile在Windows上工作?

Visual studio code 如何使Linux Makefile在Windows上工作?,visual-studio-code,makefile,Visual Studio Code,Makefile,(免责声明:我根本不是计算机科学天才,远非如此。我可能会使用不好的术语,我对此表示道歉。) 我需要使用google测试库运行一些测试,并且提供了一个Makefile来处理执行,但它不会在我的Windows机器上运行(我使用Visual Studio)。它是为Linux环境设计的,所以我不确定运行它需要修改什么。过去,我使用MinGW运行自己制作的Makefiles 下面是Makefile的外观: CC=g++ CFLAGS=-c -Wall -ggdb -I. LDFLAGS= SOURCES=

(免责声明:我根本不是计算机科学天才,远非如此。我可能会使用不好的术语,我对此表示道歉。)

我需要使用google测试库运行一些测试,并且提供了一个Makefile来处理执行,但它不会在我的Windows机器上运行(我使用Visual Studio)。它是为Linux环境设计的,所以我不确定运行它需要修改什么。过去,我使用MinGW运行自己制作的Makefiles

下面是Makefile的外观:

CC=g++
CFLAGS=-c -Wall -ggdb -I.
LDFLAGS=
SOURCES=main.c singlelinklist.c
TESTS=single_test.cpp


#TODO: Need a more elegant way of specifying objects and tests
GTESTDIR=~/environment/googletest
OBJECTS=$(SOURCES:.cpp=.o)

FLAGS   = -Iinclude

#all: $(SOURCES) $(EXECUTABLE)
    

# These next lines do a bit of magic found from http://stackoverflow.com/questions/2394609/makefile-header-dependencies
# Essentially it asks the compiler to read the .cpp files and generate the needed .h dependencies.
# This way if any .h file changes the correct .cpp files will be recompiled
depend: .depend

.depend: $(SOURCES)
    rm -f ./.depend
    $(CC) $(CFLAGS) -MM $^ >> ./.depend;

include .depend
# End .h file magic

#$(EXECUTABLE): $(OBJECTS) 
#   $(CC) $(LDFLAGS) $(OBJECTS) -o $@

#.cpp.o:
#   $(CC) $(CFLAGS) $< -o $@

clean:
#   rm -rf *o $(EXECUTABLE) test_executable
    rm -f ./.depend
    rm $(GTESTDIR)/libgtest.a
    rm $(GTESTDIR)/gtest-all.o

# Google test section
$(GTESTDIR)/libgtest.a: 
    $(CC) -isystem $(GTESTDIR) -I $(GTESTDIR) -pthread -c $(GTESTDIR)/gtest/gtest-all.cc -o $(GTESTDIR)/gtest-all.o
    ar -rv $(GTESTDIR)/libgtest.a $(GTESTDIR)/gtest-all.o

# This will also recompile if any source file is changed.
test_executable: $(GTESTDIR)/libgtest.a $(TESTS) depend
    $(CC) -isystem $(GTESTDIR) -pthread -ggdb $(TESTS) $(GTESTDIR)/gtest/gtest_main.cc $(GTESTDIR)/libgtest.a -o test_executable

test: test_executable
    ./test_executable --gtest_print_time=0
CC=g++
CFLAGS=-c-Wall-ggdb-I。
LDFLAGS=
SOURCES=main.c singlelinklist.c
测试=单次测试.cpp
#TODO:需要一种更优雅的方式来指定对象和测试吗
GTESTDIR=~/environment/googletest
对象=$(源:.cpp=.o)
标志=-i包括
#全部:$(源)$(可执行)
#接下来的几行是从中发现的一点魔力http://stackoverflow.com/questions/2394609/makefile-header-dependencies
#本质上,它要求编译器读取.cpp文件并生成所需的.h依赖项。
#这样,如果任何.h文件发生更改,将重新编译正确的.cpp文件
依赖:。依赖
.depend:$(来源)
rm-f./.取决于
$(CC)$(CFLAGS)-MM$^>>./.depend;
包括,取决于
#End.h文件魔法
#$(可执行文件):$(对象)
#$(CC)$(LDFLAGS)$(对象)-o$@
#.cpp.o:
#$(CC)$(CFLAGS)$<-o$@
清洁:
#rm-rf*o$(可执行文件)测试\u可执行文件
rm-f./.取决于
rm$(GTESTDIR)/libgtest.a
rm$(GTESTDIR)/gtest all.o
#谷歌测试组
$(GTESTDIR)/libgtest.a:
$(CC)-isystem$(GTESTDIR)-I$(GTESTDIR)-pthread-c$(GTESTDIR)/gtest/gtest-all.CC-o$(GTESTDIR)/gtest-all.o
ar-rv$(GTESTDIR)/libgtest.a$(GTESTDIR)/gtest all.o
#如果任何源文件发生更改,这也将重新编译。
test_可执行文件:$(GTESTDIR)/libgtest.a$(TESTS)依赖
$(CC)-isystem$(GTESTDIR)-pthread-ggdb$(TESTS)$(GTESTDIR)/gtest/gtest_main.CC$(GTESTDIR)/libgtest.a-o test_可执行文件
test:test\u可执行文件
./test\u可执行文件--gtest\u打印时间=0
下面是我的工作区的结构


(好像我不能嵌入图片)。

要使makefiles工作,首先需要
make
。您可以安装MinGW,它随GNU编译器工具链提供的所有工具一起提供。我已经安装了MinGW,但我一直运行在这个错误中,我忘了提到C:\Users\X\Desktop\CSCI 240 Homegration 5 X>mingw32 make Makefile:26:.依赖:没有这样的文件或目录rm-f./.依赖进程\u begin:CreateProcess(NULL,rm-f./.依赖,…)失败。make(e=2):系统找不到指定的文件。Makefile:23:目标“.depend”的配方失败mingw32 make:**[.depend]错误2您的PATH环境变量中是否有MinGW bin目录?我不确定如何检查。转到windows系统控件,扩展设置环境变量。