【发布时间】:2020-05-27 20:32:51
【问题描述】:
我正在使用 VSCode 创建一个 C++ 项目,并在尝试构建 && 调试时不断收到此错误。从控制台运行时,如果我使用 'g++ -o main 'main.cpp' 'file_1.cpp' 'file_2.cpp'' 它可以正常工作并正确编译。
我读到这与文件链接有关?有谁知道如何在 VSCode 中解决这个问题?如果有帮助,我有一个默认的 launch.json 配置文件,它会构建活动文件。
这是我的 tasks.json 文件的内容:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "shell: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
}
}
]
}
编辑:我正在使用 Debian 10 'Buster'
非常感谢
【问题讨论】:
-
我查看了 c/c++ 配置,有一个添加编译器参数的选项,但我似乎找不到任何指定文件的方法(理想情况下,它需要递归搜索工作区所有 .cpp 文件)
-
这应该在 .json 文件中。
-
@drescherjm 我正在使用 g++ 在 Linux 上编译
-
Linux 指令在这里:code.visualstudio.com/docs/cpp/config-linux
-
您可以在其中列出文件,就像您在命令行中所做的那样。您可能还想考虑使用 CMake 之类的东西,而不必一直在 tasks.json 文件中进行更改
标签: c++ linux visual-studio-code vscode-settings vscode-tasks