VSCode - C++ 未定义对“CLASS::FUNCTION"的引用 [英] VSCode - C++ undefined reference to 'CLASS::FUNCTION'
问题描述
我正在使用 VSCode 创建一个 C++ 项目,并在尝试构建 && 时不断收到此错误.调试.从控制台运行时,如果我使用 'g++ -o main 'main.cpp' 'file_1.cpp' 'file_2.cpp'' 它可以正常工作并正确编译.
I'm using VSCode to create a C++ project and keep getting this error when trying to build && debug. When running from console if I use 'g++ -o main 'main.cpp' 'file_1.cpp' 'file_2.cpp'' it works and compiles correctly.
我读到这与文件链接有关?有谁知道如何在 VSCode 中解决这个问题?如果有帮助,我有一个默认的 launch.json 配置文件来构建活动文件.
I have read that this is something to do with the linking of files? Does anyone know how to fix this in VSCode? I have a default launch.json configuration file that builds the active file if this helps.
这是我的 tasks.json 文件的内容:
Here is the contents of my tasks.json file:
{
"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'
I'm using Debian 10 'Buster'
非常感谢
推荐答案
您需要修改 tasks.json 以编译所有 .cpp .在 args
中,将 ${file}
更改为 ${workspaceFolder}/*.cpp
要运行构建任务,请按 Ctrl+Shift+B,这将在当前目录中生成一个执行文件.在终端中执行此文件以运行程序(./fileName)
You need to modify tasks.json for compile all .cpp .
In args
change ${file}
for ${workspaceFolder}/*.cpp
To run the build task press Ctrl+Shift+B, this generate a execution file in the current directory. Execute this file in the terminal for run the program (./fileName)
这篇关于VSCode - C++ 未定义对“CLASS::FUNCTION"的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!