为什么此任务配置不允许我编译多个C++ Windows上的VS代码中的文件?
因此,我已经查看了其他一些堆栈溢出问题,并在VS代码中尝试了一些任务文件中的一些内容,以编译多个C ++文件。但是,它似乎不起作用,并且有些困惑为什么它仍然没有链接。我更喜欢使用VS代码,而不是IDE,所以我真的很想让此工作。
main.cpp
#include <iostream>
int add(int x, int y);
int main(){
std::cout << add(1, 1);
return 0;
}
test.cpp
int add(int x, int y){
return x + y;
}
任务
{
"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++"
}
]
}
。
让我很棒,因为即使阅读了有关此问题的其他帖子,我似乎也无法得到这个。谢谢你!
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. 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.
main.cpp
#include <iostream>
int add(int x, int y);
int main(){
std::cout << add(1, 1);
return 0;
}
test.cpp
int add(int x, int y){
return x + y;
}
tasks.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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许输入文件路径模式
$ {workspaceFolder}/*。cpp
:ps: ps:
您想把
tasks.json
放入.vscode
文件夹中Perhaps there is something wrong with input file path pattern
${workspaceFolder}/*.cpp
:PS:
would you like to put the
tasks.json
into.vscode
folder我认为,test.cpp并未由main.cpp包括。
#include“ test.cpp”
In my opinion,the test.cpp was not been includeed by main.cpp.
#include "test.cpp"