How to let VS Code skip source files with no changes since last compiling? - visual-studio-code

Eclipse CDT can automatically compile all the changed source files (if there are) in the project directory and link them. However the default "C/C++: g++.exe build active file" task would always compile the file even there was no change since last compile. Yes, it could be done by make file. Besides that, do VSC or its extensions provide some easier way to do so?
Here is how my tasks.json looks like:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "\"${config:task.gccpath}/g++.exe\"",
"args": [
"-Wall",
"-g",
"${file}",
"-o",
"${workspaceFolder}/Debug/${relativeFileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${config:task.gccpath}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: ${config:task.gccpath}/g++.exe"
}
]
}
And here is how my launch.json looks like
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/Debug/${relativeFileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/IO/${relativeFileDirname}/",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"miDebuggerPath": "${config:task.gccpath}/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}

Related

Command Line Arguments Issue

I have an executable file a.out in my workspace that I am trying to call with the argument hello.txt.
When I run ./a.out hello.txt in the terminal, it works. However, when try to do this with VSC, hello.txt is not getting passed to the executable.
I've verified my json files extensively, but I cannot figure out where the issue is coming from. Any help would be greatly appreciated. My tasks.json and launch.json are below:
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc-9 build active file",
"command": "/usr/bin/gcc-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/a.out"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json:
{
"name": "C Launch",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": ["${workspaceFolder}/hello.txt"],
"cwd": "${workspaceFolder}"
}

How do I create output folder for MSVC generated files in Visual Studio Code?

I am following the tutorial here which shows how to use the VS C++ in Visual Studio Code.
Everything runs smoothly. The only problem is the auto-generated files (.lnk, .pdb, .exe and the likes) get generated in my src itself. How do I get the task to generate an output folder and store the auto-generated files there?
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "cl.exe build active file"
}
]
}

vscode cpp build tasks.json type:"cppbuild" error

VSCode : 1.61.0
Linux: Ubuntu 20.04.3 LTS
I'm trying to build c++ program using by VSCode.
when the run build, VSCode showing this message.
I know build tasking need matching launch.json file's preLaunchTask with tasks.json file's label. and I'm already set it.
tasks.json
{
"tasks": [
{
"type": "cppbuild", // but "shell" is working
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
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++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
The problem is, if I change the "type" value in tasks.json, from shell to cppbuild, It doesn't work and show the error message like to.
showing error message when the run build
what is different "cppbuild" and "shell"? and What should I do how using "cppbuild" value?
Te values of cppbuild are fine. Try changing in launch.json the value:
"preLaunchTask": "C/C++: g++ build active file",
to:
"preLaunchTask": "cppbuild",
The difference between shell and cppbuild is that the first open the BASH and runs a command you write, the second, cppbuild, runs an specific binary (or program).

VS Code -- Unexpected Output Format /ERROR\

Im new to stackoverflow and VS Code. When I tried to debug my code I got error message, and couldn't fix it.
I uploaded the error message
and;
here is mylaunch.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 - Etkin dosyayı derle ve dosyada hata ayıkla",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb için düzgün yazdırmayı etkinleştir",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
and task.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\TDM-GCC-64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\TDM-GCC-64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"
}
my main.cpp file is simply printes "Hello"
I installed MinGW and its directory is : C:\MinGW<
I hope there is someone who can help me.
I encountered the same problem recently. It seems that the auto-generated tasks.json is not set correctly and the executable is created in the root directory. This can be fixed by changing the type from "cppbuild" to "shell".
{
"tasks": [
{
"type": "shell",
...
}
],
"version": "2.0.0"
}

Is it possible to set a task.json for all c++ files in VSCode?

I'd like to give VSCode a try.
Is it possible to set compile and build commands for all .cpp files? Just like in Geany? And it is possible to do that for every supported language?
Searching here and there it seems that I have to set it in task.json for each project (even the link to iostream)
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "Example:/Your/path/to/gdb",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe"
],
"problemMatcher": { "owner": "cpp", "fileLocation": ["relative", "${workspaceRoot}"],
"pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5 }
}
}
That's the solution for C/C++ Extension. Maybe you have to set a breakpoint at the end of the .cpp file.
Or you can install the code-runner Extension.
You can add the two files to C:/Users/someone/AppData/Roming/Code/User/ so that you can compile for all .cpp files.
From here: https://github.com/Microsoft/vscode/issues/1435#issuecomment-433324050
Global tasks in a task.json file are still on the agenda (to get parity with launch.json). However it is a matter of priorities when they will come.
So the answer is: not yet.