[英]Why does this task config not allow me to compile multiple C++ files in VS Code on Windows?
So I have looked at some other Stack Overflow questions, and tried a few things to my task file in VS Code to compile multiple C++ files.因此,我查看了其他一些 Stack Overflow 问题,并在 VS Code 中对我的任务文件进行了一些尝试,以编译多个 C++ 文件。 However, it isn't seeming to work and am a bit confused why it is still not linking.
但是,它似乎不起作用,并且有点困惑为什么它仍然没有链接。 I'd prefer to use VS Code and not an IDE, so I really want to get this working.
我更喜欢使用 VS Code 而不是 IDE,所以我真的很想让它工作。
main.cpp主文件
#include <iostream>
int add(int x, int y);
int main(){
std::cout << add(1, 1);
return 0;
}
test.cpp测试.cpp
int add(int x, int y){
return x + y;
}
tasks.json任务.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "g++.exe build",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.cpp",
"-o",
"${workspaceFolder}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "g++"
}
]
}
My folders are as follows:我的文件夹如下:
Any help would be amazing as I can't seem to get this even after reading other posts about this issue.任何帮助都会令人惊叹,因为即使在阅读了有关此问题的其他帖子后,我似乎也无法得到这个。 Thank you!
谢谢!
Perhaps there is something wrong with input file path pattern ${workspaceFolder}/*.cpp
:输入文件路径模式
${workspaceFolder}/*.cpp
可能有问题:
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.cpp", // Would you like to change it to ${workspaceFolder}\\*.cpp
"-o",
"${workspaceFolder}\\${fileBasenameNoExtension}.exe"
],
PS: would you like to put the tasks.json
into .vscode
folder PS:你
tasks.json
放到.vscode
文件夹吗
In my opinion,the test.cpp was not been includeed by main.cpp.在我看来,test.cpp 没有包含在 main.cpp 中。 #include "test.cpp"
#include "test.cpp"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.