# Debug C++ on Ubuntu with Visual Studio Code ### Requirements * g++ (by installation of the development package [`build-essential`](https://linuxconfig.org/how-to-install-g-the-c-compiler-on-ubuntu-20-04-lts-focal-fossa-linux)) * [C/C++ Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) * [CodeLLDB Extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) ### Instructions Step 1: Edit `launch.json` file ``` { "version": "0.2.0", "configurations": [ { "name": "lldb launch", "type": "lldb", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "preLaunchTask": "C/C++: g++ build active file" } ] } ``` Step 2: Edit `tasks.json` file ``` { "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-fdiagnostics-color=always", "-std=c++17", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ] } ``` Step 3: Create and edit `main.cpp` file ``` #include #include using namespace std; int main(){ string s = "Hello World"; vector v = {0, 1, 2, 3}; for(auto item: v){ cout << "Hello World " << item << endl; } return 0; } ``` Step 4: Run & Debug Click Run & Debug (Ctrl+Shift+D), then click Start Debugging (F5) ## References * https://code.visualstudio.com/docs/cpp/config-clang-mac * https://stackoverflow.com/questions/64568431/vs-code-debugger-not-operational-on-macos