I recently installed anaconda and added it to my visual studio code. I had previously installed C++
but now after setting up python interpreter on visual studio code i can't figure out how to switch back to my C++ compiler
Does anyone knows how to?
Edit:
My vs code folder looks like:
->.vscode
->settings.json (1)
->c_cpp_properties.json
->launch.json
->settings.json (2)
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": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
]
}
My settings.json (2):
{
"code-runner.runInTerminal": true,
"workbench.colorTheme": "Abyss",
"C_Cpp.updateChannel": "Insiders",
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook"
},
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "right"
},
"notebook.lineNumbers": "on",
"python.analysis.completeFunctionParens": true,
"[cpp]": {
"editor.wordBasedSuggestions": false,
"editor.suggest.insertMode": "replace",
"editor.semanticHighlighting.enabled": true
}
}
Settings.json (1):
{
"python.pythonPath": "C:\\Users\\HP\\.conda\\envs\\myenv\\python.exe"
}
My c_cpp_properties file:
{
"configurations": [
{
"name": "Win32",
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64",
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin",
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/include",
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib",
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"C:/Users/HP/AppData/Local/Programs/Python/Python39/Scripts"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": ""
}
],
"version": 4
}
I think i have messed up my settings.json but i don't understand much about vs code yet so i can't figure out how to fixed it.
Related
I have a C++ project running in VS Code. The CMake file has been created. Opening VS Code then triggers the creation of the settings.json file under .vscode. I then create the launch.json file. Things work properly. Later, I somehow trigger the creation of another debug configuration (from the C/C++ Runner extension?). My setting.json file goes from:
{
"cmake.sourceDirectory": "${workspaceFolder}/hello-world"
}
to:
{
"cmake.sourceDirectory": "${workspaceFolder}/hello-world",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wconversion",
"-Wnull-dereference",
"-Wsign-conversion"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
]
}
My launch.json file also has this extra section added:
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/machine01/dev-workspace/repo01/hello-world",
"program": "/home/machine01/dev-workspace/repo01/hello-world/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
This automatic settings creation is very convenient. How do I trigger this again? I have tried many things to no avail.
I am using the Eigen library (https://eigen.tuxfamily.org/dox/GettingStarted.html) for some computations.
The program that I am running is:
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}
In their documentation by recommend compiling with:
g++ -I /path/to/eigen/ my_program.cpp -o my_program
If I run this, it compiles and runs... But now I would like to able to debug through the code.
The .json files generated I am using are:
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-I",
"${eigen}",
"${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"
}
]
}
and
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/pc/eigen/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
This configuration just runs the code but does not stick the debugger to it.
Would really appreciate the help!
Ok, so this worked for me:
1º Download Eigen:
https://eigen.tuxfamily.org/index.php?title=Main_Page
2º Create a symbolic link to the eigen folder
sudo ln -s location/of/Eigen/Folder /usr/local/include/
3º Can compile code with:
g++ my_program.cpp -o my_program
4º To "better debug" Eigen use the custom python printer for gdb
https://gitlab.com/libeigen/eigen/-/blob/master/debug/gdb/printers.py
a) Create a hidden file called gdbinit
touch ~/.gdbinit
b) Place the following code in it:
python
import sys
sys.path.insert(0, '/path/to/eigen/printer/directory') #In my case it was /home/pc/eigen/debug/gdb
from printers import register_eigen_printers
register_eigen_printers (None)
end
Note: VScode worked straight out of the box (F5 and debug mode was on!)
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"
}
I am trying to configure the Debugger in VSCode
I looked through official documentation to setup the VSCode debugger for C/C++ but it's not working.
Documentation states the steps for setting up vscode debugger for
powershell in windows.
But I am trying to set-up debugger with git bash as my default integrated terminal in windows.
I have added git bash as default terminal but I am not able to setup debugger with git bash as integrated terminal.
Default configuration files :
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.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:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
The property :
"externalConsole": false
is set to false as I want VSCode to use the integrated default bash terminal instead of using external terminal for debugging.
tasks.json :
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}
settings.json
{
"files.associations": {
"iostream": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
With the above configuration, when I start the debugging it gives me the following error:
It seems like the command property in tasks.json is incorrect,
as bash converts
"C:\MinGW\bin\g++.exe" -> "C:MinGWbing++.exe"
and gives error: "no command found" because back-slash('\') in bash is an escape character.
Now changing above path in tasks.json to bash style :
"command": "C:/MinGW/bin/g++.exe"
resolves the above error, but now it gives same error for variable ${file} as this path-variable gets dynamically set to current open file .cpp.
I have been working on this debugging issue for last few days, but haven't found any workaround yet.
How can I change/update by configuration files to use git bash as default integrated terminal in VSCode for debugging.
It seems like the command property in tasks.json is incorrect, as bash converts
"C:\MinGW\bin\g++.exe" -> "C:MinGWbing++.exe"
Then try a cygwin-like path:
/c/MingW/bin/g++.exe
# or
/C/MingW/bin/g++.exe
Check if it is interpreted correctly by the git bash session then.
I tried compiling and debugging c++ programs in vscode with wsl, compiling succeeded, but when I tried to press F5 to debug, the error is that the pipe program failed to start. Here is my launch.json.
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/maxu/projects/helloworld/helloworld.out",
"args": [""],
"stopAtEntry": true,
"cwd": "/home/maxu/projects/helloworld/",
"environment": [],
"externalConsole": true,
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/c": "${env:systemdrive}/",
"/usr": "C:\\Users\\maxu1\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr"
}
}
]
}
here is the error message
error message
I tried to modify the parameter "pipeProgram" to "c:\windows\system32\bash.exe", but also failed.
I have a similar problem as yours except that my pipe program is ssh.exe under c:\windows\system32\openssh.
Here is how I work through it: copy openssh folder to c:\ and add that path to my user path environment variable. You can have a try.
I don't know if the windows system folders are accessible from vscode.