Set C/C++ Runner to use integrated terminal by default - c++

The C/C++ Runnner extension (link here) automatically creates debug configurations for C/C++ projects, and for example generates a .json file like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/Otávio Augusto Silva/Documents/Code/C++/dynamic_array",
"program": "c:/Users/Otávio Augusto Silva/Documents/Code/C++/dynamic_array/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
My question is, how do I make the extension set the externalConsole option to false by default? It always creates the config file to use an external console.

Go to Extensions search for Code Runner and then select Manage it's the settings icon directly to the right of Disable, Uninstall and select Extension Settings.
Search for code-runner.runInTerminal and set it true.

Related

C++ for VS code: Unable to start debugging [duplicate]

I just switch from Netbeans to visual studio code, and i cannot debug c++, the error was Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path....
I tried to follow the c/c++ debug guide from visual studio code website that i searched from google, but it failed to run the application, but i can compile c++ from Ctrl + Shift + B so my task.json file is correct, so here are my task.json file and launch.json file.
{
//Task.json
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["-pipe", "-std=c++14", "${fileBasename}", "-lm"],
"showOutput": "always"
}
//Launch.json
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
I just fixed it by doing the following (under windows)
Installed TDM-GCC MinGW Compiler from https://sourceforge.net/projects/tdm-gcc/?source=typ_redirect
use default installation path options.
Added these folders to PATH environment variable
C:\TDM-GCC-64\bin
C:\TDM-GCC-64\gdb64\bin
In your launch.json add the path to gdb debugger, your windows section should look like the code below
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:/TDM-GCC-64/gdb64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
Restart Visual Studio Code and try compile (ctrl+shift+b) and run the debugger (f5)
Remark: Like others had mentioned you should add the -g option in your tasks.json args so that the executable will be built with debugging information.

I can't debug C in VSCode/CodeBlocks or Any IDE

This is my 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": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\gdb32.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
It was GDB.exe here earlier, But it said it couldn't find it , Even I couldn't find it..
So I put gdb32.exe as i was able to find that out , But it still didn't debug anything
i am fed up of this problem now...
Code Blocks says Please specify executable path,It can't be found
Please help, Thanks
Code::Blocks can be installed without MinGW, which is okay as MinGW-w64 is much better maintained. But MinGW-w64 needs to be installed separately.
You can download a standalone MinGW-w64 from https://winlibs.com/ and the site also explains on how to add this compiler and debugger to the settings.

Proble in debuging c++ code with visual studio code, with lunch.json file

I have Problem in debugging c++ programs in Visual studio code. Although, debugging was working before. I had not change any configuration or setting. When i opened visual studio code today then i saw that error.
Image
lunch.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 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
I have not changed anything in system/vc code/ configuration etc.
Then, why debugging stops working.
The program setting specifies the program you want to debug. Here it is set to the active file folder ${fileDirname} and active filename with the .exe extension ${fileBasenameNoExtension}.exe, which if helloworld.cpp is the active file will be helloworld.exe.
The main problem is vccode is not able to find the current file for debugging.
These are some links that might work for you.
Docs
Configuration

Using .natvis file to visualise C++ objects in VS Code

According to this link, .natvis files can be used to visualise native objects. Specifically, I would like to be able to inspect Eigen::Matrix objects using this .natvis file.
However, the link above does not contain any information on how to actually use a .natvis file in VS Code. Is it possible using a custom .natvis file?
Here is my launch.json file for reference:
{
// 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++-8 build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++-8 build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
The launch.json file has has a visualizerFile option:
{
"name": "g++-8 build and debug active file",
"visualizerFile": "${workspaceFolder}/path/to/file.natvis",
"showDisplayString": true,
...
},
Some more documentation here (see the visualizerFile and showDisplayString table entries):
https://learn.microsoft.com/en-us/cpp/build/launch-vs-schema-reference-cpp?view=vs-2019#c-linux-properties
You might also be interested in this issue:
https://github.com/Microsoft/vscode-cpptools/issues/925

How to make VS Code not open a terminal when debugging?

I've installed VS Code on Ubuntu 17.04.
When I debug my C++ application, the output is displayed in a dedicated terminal and not within VS Code itself (like Eclipse does).
How do I make VS Code display output within the editor itself, i.e., not open another terminal?
My launch configuration is as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": ["foo", "bar", "baz"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++"
}
]
}
I'd hoped that setting externalConsole to false would solve the problem. However, it didn't change anything.
For a C++ project, use "externalConsole": false, as follows:
This will open integrated terminal instead of external terminal. You can use "internalConsoleOptions": "openOnSessionStart" if you want to open the debug console instead of the integrated/external console:
For a Java project, use , "console": "integratedTerminal" in the configurations file:
Use "console": "internalConsole" if you do not want to see any debug console.
Set "console":"none" like such:
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}"
"cwd": "${workspaceFolder}"
"console": "none"