[英]VSCode - C++ undefined reference to 'CLASS::FUNCTION'
I'm using VSCode to create a C++ project and keep getting this error when trying to build && debug.我正在使用 VSCode 创建一个 C++ 项目,并在尝试构建 && 调试时不断收到此错误。 When running from console if I use 'g++ -o main 'main.cpp' 'file_1.cpp' 'file_2.cpp'' it works and compiles correctly.
从控制台运行时,如果我使用 'g++ -o main 'main.cpp' 'file_1.cpp' 'file_2.cpp'' 它可以正常工作并编译。
I have read that this is something to do with the linking of files?我读到这与文件链接有关? Does anyone know how to fix this in VSCode?
有谁知道如何在 VSCode 中解决这个问题? I have a default launch.json configuration file that builds the active file if this helps.
我有一个默认的 launch.json 配置文件,如果有帮助,它会构建活动文件。
Here is the contents of my tasks.json file:这是我的 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"
}
}
]
} }
EDIT: I'm using Debian 10 'Buster'编辑:我正在使用 Debian 10 'Buster'
Many thanks非常感谢
You need to modify tasks.json for compile all.cpp.编译all.cpp需要修改tasks.json。 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.在
args
中,将${file}
更改为${workspaceFolder}/*.cpp
要运行构建任务,请按 Ctrl+Shift+B,这会在当前目录中生成一个执行文件。 Execute this file in the terminal for run the program (./fileName)在终端中执行此文件以运行程序 (./fileName)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.