I am a beginner in c++ and vs-code but have been tasked to use/develop an existing c++ project (I have used python and sublime before this).
I want to be able to configure vs code so that I can easily debug and compile code without to much hassle.
Currently, this is the way I do it:
- Make some change in the code, for example in $basedir/src/folder1/file.cpp
- Go to $basedir in the terminal, and run
- a) make
- b) wait for it to go through a bunch of folders to find a file that has been changed.
- c) cd $basedir/programs/dawn; make clean; make
- And finally to run the project a type:
$basedir/programs/project/projectname inputfile.json
What I want to do is to just press F5 (for debugging, or ctrl+F5 to run), but I don't know how to set everything up is vs code. Can someone help me?
These are my configuration files:
In c_cpp_properties.json I have referenced two other projects, but I also have to add the current project include-directory in order for vs-code to not complain about include-file, etc (I thought it would automatically find files in the project with ${workspaceFolder}/**
)
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"~/otherproject1/include/",
"~/otherproject2/include/",
"~/Documents/projectname/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
{
tasks.json
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"cd ${workspaceFolder};",
"make;",
"make clean -C programs/projectname;",
"make -C programs/projectname;",
],
"options": {
"cwd": "/usr/bin"
}
}
],
"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": "${workspaceFolder}/programs/projectname inputfile.json",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}