Note that I'm using Windows 10 x64, MinGW 9.2.0, VSCode 1.54.1.
My goal is to build and run multiple .cpp files in current folder and different levels subfolders I use. I've tried it configuring tasks.json and c_cpp_properties.json files with help of these articles: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
https://code.visualstudio.com/docs/cpp/config-mingw
VS Code will not build c++ programs with multiple .ccp source files
I tried to configure my c_cpp_properties.json by adding this instruction:
"includePath": [
"${workspaceFolder}/*"
]
And I modified also my tasks.json like this:
"args": [
"-std=c++17",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
]
It actually works for the case I would like to build multiple .cpp files in the main directory. I have a folder vscode_prj, then I have .vscode inside (I attach all my configuration files here), and all files I have inside vscode_prj are build OK, but if I try to create a new folder inside vscode_prj, for example vscode_prj/project1 and I have a few .cpp files inside project1 it's not working and I can't build these files. I just recieve this error:
g++.exe: error: C:\Users\username\folderfolder\_prj\vscode_prj\*.cpp: Invalid argument
g++.exe: fatal error: no input files
compilation terminated.
So, as I understand, compiler just can't find my source files inside subfolder. And it doesn't matter if I have one source file in this folder or several, it's just not build. I appreciate any help and excuse me for my English, it's my first question here, because I just don't know what to do. Thanks.
Attachments: vscode_prj/.vscode/c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/*"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-std=c++17"
]
}
],
"version": 4
}
vscode_prj/.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-std=c++17",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
vscode_prj/.vscode/launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Сборка и отладка активного файла",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Включить автоматическое форматирование для gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
vscode_prj/.vscode/settings.json:
{
"files.associations": {
"*.tcc": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"string": "cpp",
"iomanip": "cpp"
}
}
"${workspaceFolder}\\*.cpp",to"${workspaceFolder}\\myfoldername\\*.cpp",You can put multiple wildcard similar entries on consecutive lines. I don't know if"${workspaceFolder}\\*\\*.cpp",would work on windows."${workspaceFolder}\\*\\*.cpp"unfortunately doesn't work for me on Windows, but this one"${workspaceFolder}\\myfoldername\\*.cpp"works properly, it's not so conveniently I would like it to be, but it works and it's quite enough for me for now.