【问题标题】:Having trouble configuring VS code for c++ programs为 C++ 程序配置 VS 代码时遇到问题
【发布时间】:2018-10-26 12:36:05
【问题描述】:

我在 VS 代码中编译 c++ 程序时遇到了一些麻烦。我跟着这个答案:How do I set up Visual Studio Code to compile C++ code?

我的 Makefile 是

CC=g++
CFLAGS=-Wall
.SUFFIXES = .cpp
objs:=$(wildcard *.cpp)
targets:=$(objs:.cpp= )

.PHONY:all
all: $(targets)
.cpp:
    $(CC) $(CFLAGS) -std=c++11 -o $@ $< 

我只想编译这个在当前窗口中打开的文件,比如 1.cpp,这个文件没有任何外部依赖

当我尝试编译我的文件时(按我链接的答案中给出的 f8)我收到以下错误:

'make' is not recognized as an internal or external command,
operable program or batch file.

我是初学者,对 Makefile 了解不多,我们将不胜感激。 谢谢!
编辑: 我正在使用用于 linux 的 Windows 子系统来编译我的程序,而不是 mingw 或 cygwin。

编辑:
现在我可以使用 make 但我认为我的 Makefile 有问题。

【问题讨论】:

  • 你可能需要自己安装make
  • @JETM 我已经安装了(请看这个:stackoverflow.com/questions/11934997/…
  • 我正在使用 linux(bash) 的 windows 子系统作为终端来编译我的程序
  • 那么问题是VSCode没有在正确的地方寻找make。我不知道更多,但也许这个线索可以帮助你搜索。
  • make Makefile 是一个非常糟糕的命令,可能会覆盖您的 makefile。你想要的是make -f Makefile

标签: c++ makefile compiler-errors visual-studio-code


【解决方案1】:

我想出了一个简单的方法:
args 至少在我的系统上不起作用。

所以,更改命令(tasks.json 的第 3 行)

"command": "g++ -Wall -std=c++14 ${relativeFile};./a.out < input.txt

现在只需一键编译并运行!

【讨论】:

    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2019-12-22
    • 2017-12-04
    • 1970-01-01
    相关资源
    最近更新 更多