我正在尝试弄清楚如何在 vs 代码环境中编译我的 c++ 代码。
我可以使用 g++ 进行编译,但我还无法在 vs 代码中弄明白。
我使用 BeeOnRope 从这个问题中得到的答案来设置我的构建命令和相关的热键。
How do I set up Visual Studio Code to compile C++ code?
出来的错误是这样的
make: *** No rule to make target `Makefile'. Stop. The terminal process terminated with exit code: 2
编辑:处理我的 tasks.json 后,它看起来像这样,但我仍然遇到上面显示的相同错误。
{
"version": "2.0.0",
"command": "make",
"tasks":[
{
"label": "Makefile",
"group": "build",
// Show the output window only if unrecognized errors occur.
"presentation": {"reveal": "always"},
// Pass 'all' as the build target
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
最佳答案
在您的 tasks.json 中,添加/编辑“command”和“args”字段以获得您将手动运行的构建命令行。这可能是 g++、make 或其他任何东西。看这里:
https://code.visualstudio.com/docs/editor/tasks
更新: 查看您发布的 tasks.json 文件,您的命令需要进入任务。像这样:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "My Build",
"group": "build",
"type": "shell",
"command": "g++",
"args": [
"-o", "LexParse", "Lexxy.cpp", "Parzival.cpp"
]
}
]
}
PS,这里格式化代码的一种方法是全部缩进:
int main
{
[]( auto world ) { return "Hello"s + world; } ( ", World!" );
}
另一种方法是用三个反引号包裹它(不需要缩进,虽然我在这里这样做是为了让反引号内有反引号):
```
int main
{
[]( auto world ) { return "Hello"s + world; } ( ", World!" );
}
```
关于c++ - 如何在 visual studio 代码中创建目标 'makefile'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54678838/