Showing posts with label VSCode. Show all posts
Showing posts with label VSCode. Show all posts

Tuesday, 30 April 2024

VS Code Extension for YAML & Kubernetes

In VS Code's Extensions Marketplace, search for YAML and install YAML by Red Hat. 

The following steps show how to enable support for Kubernetes.

Upon installation, on extension's tab page, click on the cog and choose Extension Settings.

In settings: find Yaml: Schemas and click on Edit in settings.json

... and in that file add the following:

    "yaml.schemas": {  
        "kubernetes": "*.yaml"
    }



After this, in YAML file, type in apiVersion (the first required property of the Kubernetes YAML definition file) and auto-completion and auto-indentation for Kubernetes YAML files will kick in:

In case of errors in YAML formatting or Kubernetes YAML file not matching the Kubernetes YAML schema, this extension will show an error:





Monday, 20 December 2021

Installing Python3 on Mac Big Sur

Mac comes with Python 2 by default and I wanted to install and use Python 3. I installed it by using brew

% brew install python3
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
abi-compliance-checker     gotify                     pam-reattach
abi-dumper                 hurl                       payload-dumper-go
biber                      imap-backup                pip-audit
brigade-cli                isa-l                      pocsuite3
chroma                     jsonschema                 rpki-client
coursier                   kubernetes-cli@1.22        salt-lint
djhtml                     lua-language-server        sevenzip
dynomite                   mcfly                      statix
fastp                      mist                       tsduck
goawk                      openliberty-jakartaee9     vtable-dumper
goplus                     openliberty-webprofile9
==> Updated Formulae
Updated 1431 formulae.
==> Deleted Formulae
ape             es              jerasure        makepp          swiftplate
balance         eventlog        kakasi          marst           torrentcheck
bbcolors        flasm           l-smash         mboxgrep        udns
colorsvn        fondu           libbind         md              whitedb
contacts        gconf           liberasurecode  namazu          xidel
csv-fix         gcore           libmill         postmark        xtail
dlite           gf-complete     libopendkim     redsocks        zdelta
dnsrend         git-hooks       libpuzzle       sdhash
drip            git-sh          libvbucket      shorten
dshb            henplus         m2c             srmio
eject           httptunnel      magnetix        svdlibc
==> New Casks
appflowy            finalshell          projector           teamspeak-client
appium-inspector    folder-colorizer    schildichat         tidgi
centered            grammarly-desktop   sitala              volley
citrix-workspace    handyprintpro       soundtoys           wolai
cron                linearmouse         spaceid             xstation5
emmetapp            ludwig              supermjograph
equinox             macrorecorder       tablecruncher
==> Updated Casks
Updated 648 casks.
==> Deleted Casks
air-connect                              lelivrescolairefr
aja-system-test                          napari
anka-build-cloud-registry                octoscreen
asc-timetables                           platelet
avast-secureline-vpn                     pullover
chameleon-ssd-optimizer                  punto-switcher
chocolat                                 qit
domainbrain                              river-sparkle
drama                                    scrutiny
everweb                                  tmnotifier
freeter                                  unity-linux-support-for-editor
gitbook                                  unity-lumin-support-for-editor
inboard                                  visicut

python@3.9 3.9.6 is already installed but outdated (so it will be upgraded).
==> Downloading https://ghcr.io/v2/homebrew/core/gdbm/manifests/1.22
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gdbm/blobs/sha256:7e9737ec99942
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2021-
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:1b
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/1.1/manifests/1.1.1m
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/1.1/blobs/sha256:ad0413
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/readline/manifests/8.1.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/readline/blobs/sha256:c596199dc
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/sqlite/manifests/3.37.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/sqlite/blobs/sha256:ae0b38a858a
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.9/manifests/3.9.9
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.9/blobs/sha256:4b56d09
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Upgrading python3
  3.9.6 -> 3.9.9 

==> Installing dependencies for python@3.9: gdbm, ca-certificates, openssl@1.1, readline and sqlite
==> Installing python@3.9 dependency: gdbm
==> Pouring gdbm--1.22.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/gdbm/1.22: 24 files, 957.9KB
==> Installing python@3.9 dependency: ca-certificates
==> Pouring ca-certificates--2021-10-26.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2021-10-26: 3 files, 208.5KB
==> Installing python@3.9 dependency: openssl@1.1
==> Pouring openssl@1.1--1.1.1m.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/openssl@1.1/1.1.1m: 8,081 files, 18.5MB
==> Installing python@3.9 dependency: readline
==> Pouring readline--8.1.1.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/readline/8.1.1: 48 files, 1.6MB
==> Installing python@3.9 dependency: sqlite
==> Pouring sqlite--3.37.0.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/sqlite/3.37.0: 11 files, 4.3MB
==> Installing python@3.9
==> Pouring python@3.9--3.9.9.big_sur.bottle.tar.gz
==> /usr/local/Cellar/python@3.9/3.9.9/bin/python3 -m ensurepip
==> /usr/local/Cellar/python@3.9/3.9.9/bin/python3 -m pip install -v --no-deps -
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python@3.9/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.9/site-packages

tkinter is no longer included with this formula, but it is available separately:
  brew install python-tk@3.9

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺  /usr/local/Cellar/python@3.9/3.9.9: 3,080 files, 55.0MB
==> `brew cleanup` has not been run in the last 30 days, running now...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /usr/local/Cellar/gdbm/1.20... (24 files, 825.0KB)
Removing: /Users/bojan/Library/Caches/Homebrew/gdbm--1.20... (221KB)
Removing: /Users/bojan/Library/Caches/Homebrew/mpdecimal--2.5.1... (548.3KB)
Removing: /usr/local/Cellar/openssl@1.1/1.1.1k... (8,071 files, 18.5MB)
Removing: /Users/bojan/Library/Caches/Homebrew/openssl@1.1--1.1.1k... (5.4MB)
Removing: /usr/local/Cellar/python@3.9/3.9.6... (3,085 files, 54.7MB)
Removing: /Users/bojan/Library/Caches/Homebrew/python@3.9--3.9.6... (13.6MB)
Removing: /usr/local/Cellar/readline/8.1... (48 files, 1.6MB)
Removing: /Users/bojan/Library/Caches/Homebrew/readline--8.1... (536KB)
Removing: /Users/bojan/Library/Caches/Homebrew/rtmpdump--2.4+20151223_1... (170.2KB)
Removing: /usr/local/Cellar/sqlite/3.36.0... (11 files, 4.2MB)
Removing: /Users/bojan/Library/Caches/Homebrew/sqlite--3.36.0... (2MB)
Removing: /Users/bojan/Library/Caches/Homebrew/xz--5.2.5... (417.6KB)
Removing: /Users/bojan/Library/Caches/Homebrew/you-get--0.4.1536... (2.2MB)
Removing: /Users/bojan/Library/Caches/Homebrew/xz_bottle_manifest--5.2.5... (5.7KB)
Removing: /Users/bojan/Library/Caches/Homebrew/rtmpdump_bottle_manifest--2.4+20151223_1... (7KB)
Removing: /Users/bojan/Library/Caches/Homebrew/sqlite_bottle_manifest--3.36.0... (5.9KB)
Removing: /Users/bojan/Library/Caches/Homebrew/openssl@1.1_bottle_manifest--1.1.1k... (6KB)
Removing: /Users/bojan/Library/Caches/Homebrew/python@3.9_bottle_manifest--3.9.6... (15.4KB)
Removing: /Users/bojan/Library/Caches/Homebrew/readline_bottle_manifest--8.1... (5.5KB)
Removing: /Users/bojan/Library/Caches/Homebrew/you-get_bottle_manifest--0.4.1536... (11.2KB)
Removing: /Users/bojan/Library/Caches/Homebrew/gdbm_bottle_manifest--1.20... (5.2KB)
Removing: /Users/bojan/Library/Caches/Homebrew/mpdecimal_bottle_manifest--2.5.1... (5.2KB)
Removing: /Users/bojan/Library/Logs/Homebrew/gdbm... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/mpdecimal... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/rtmpdump... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/readline... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/sqlite... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/xz... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/you-get... (64B)
Removing: /Users/bojan/Library/Logs/Homebrew/python@3.9... (2 files, 2.4KB)
Pruned 0 symbolic links and 2 directories from /usr/local
==> Upgrading 1 dependent:
Disable this behaviour by setting HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
you-get 0.4.1536 -> 0.4.1555
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/manifests/3.10.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.10/blobs/sha256:c4f29a
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/you-get/manifests/0.4.1555
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/you-get/blobs/sha256:df0dc12c74
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Upgrading you-get
  0.4.1536 -> 0.4.1555 

==> Installing dependencies for you-get: python@3.10
==> Installing you-get dependency: python@3.10
==> Pouring python@3.10--3.10.1.big_sur.bottle.tar.gz
==> /usr/local/Cellar/python@3.10/3.10.1/bin/python3 -m ensurepip
==> /usr/local/Cellar/python@3.10/3.10.1/bin/python3 -m pip install -v --no-deps
🍺  /usr/local/Cellar/python@3.10/3.10.1: 3,132 files, 56MB
==> Installing you-get
==> Pouring you-get--0.4.1555.big_sur.bottle.tar.gz
==> Caveats
To use post-processing options, run `brew install ffmpeg` or `brew install libav`.
==> Summary
🍺  /usr/local/Cellar/you-get/0.4.1555: 736 files, 8.5MB
==> Running `brew cleanup you-get`...
Removing: /usr/local/Cellar/you-get/0.4.1536... (845 files, 8.6MB)
==> Checking for dependents of upgraded formulae...
==> No broken dependents found!
==> Caveats
==> python@3.9
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python@3.9/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.9/site-packages

tkinter is no longer included with this formula, but it is available separately:
  brew install python-tk@3.9

See: https://docs.brew.sh/Homebrew-and-Python
==> you-get
To use post-processing options, run `brew install ffmpeg` or `brew install libav`.


If zsh configuration file does not exist, create it and open it:

% touch ~/.zshrc
% vi ~/.zshrc

Type in it:

export PATH=/usr/local/opt/python@3.9/libexec/bin:$PATH

Restart the terminal.

% which python
/usr/local/opt/python@3.9/libexec/bin/python
% python --version
Python 3.9.9

If using VSCode, restart it and it will also pick up this version of Python in its Terminal.


Wednesday, 19 February 2020

How to install and use Boost C++ Libraries in CMake project on Ubuntu



Download Boost archive from Version 1.72.0 (that is the current version at the time of writing).

Go to the directory where you want to install Boost:

$ cd ~/dev

Unpack the downloaded archive (tar will create boost_1_72_0 directory):

$ tar --bzip2 -xf ~/Downloads/boost_1_72_0.tar.bz2 
$ ls
boost_1_72_0  github  gnome  go  ssh-keys  vm  vm-shared

Let's see the content of ~/dev/boost_1_72_0/:

~/dev/boost_1_72_0$ ls -A1
boost
boost-build.jam
boostcpp.jam
boost.css
boost.png
bootstrap.bat
bootstrap.sh
doc
index.htm
index.html
INSTALL
Jamroot
libs
LICENSE_1_0.txt
more
README.md
rst.css
status
tools


Let's see the content of ~/dev/boost_1_72_0/boost/:

~/dev/boost_1_72_0/boost$ ls -A1
accumulators
algorithm
align
aligned_storage.hpp
align.hpp
any.hpp
archive
array.hpp
asio
asio.hpp
assert.hpp
assign
assign.hpp
atomic
atomic.hpp
beast
beast.hpp
...

lambda
...


Many Boost libraries are header-only which means we don't need to build them, it is only necessary to add relevant header in the source code and path to it to compiler (-I) options.

Boost documentation page Getting Started on Unix Variants contains a short demo code and I'm gonna use it here. It uses boost/lambda/lambda.hpp header from so let's see the content of ~/dev/boost_1_72_0/boost/lambda/ to confirm it's there:


~/dev/boost_1_72_0/boost/lambda$ ls -A1
algorithm.hpp
bind.hpp
casts.hpp
closures.hpp
construct.hpp
control_structures.hpp
core.hpp
detail
exceptions.hpp
if.hpp
lambda.hpp
loops.hpp
numeric.hpp
switch.hpp

Let's create a project in VSCode with following structure:

.vscode/tasks.json
build/
src/main.cpp
.gitignore
CMakeLists.txt


.vscode/tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "CMake && make",
            "options": {
                "cwd": "${workspaceFolder}/build"
            },
            "command": "cmake make -DCMAKE_BUILD_TYPE=Debug .. && make -j 4",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}


src/main.cpp:

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main() {
    std::cout << "main()" << std::endl;

    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;
    std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " );

    return 0;
}


CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)
project(boost-demo)
set(SOURCE src/main.cpp)
set(BOOST_ROOT "$HOME/dev/boost_1_72_0")
include_directories(include)
add_executable(${PROJECT_NAME} ${SOURCE})


Press CTRL+SHIFT+B in order to trigger building the project:


> Executing task: cmake make -DCMAKE_BUILD_TYPE=Debug .. && make -j 4 <

-- Configuring done
-- Generating done
-- Build files have been written to: /home/bojan/dev/github/boost-demo/build
Scanning dependencies of target boost-demo
[ 50%] Building CXX object CMakeFiles/boost-demo.dir/src/main.cpp.o
[100%] Linking CXX executable boost-demo
[100%] Built target boost-demo

Terminal will be reused by tasks, press any key to close it.


The output is an executable which we can run now:


~/dev/github/boost-demo$ ./build/boost-demo 
main()
1
3 2
6 3
9 4
12 7
21 ^C


The example above shows how it's simple to include Boost headers in C++ CMake project.

For some Boost features, we need to compile and install certain Boost libraries.


How to compile and install Boost binaries?



~/dev/boost_1_72_0$ ./bootstrap.sh --help
`./bootstrap.sh' prepares Boost for building on a few kinds of systems.

Usage: ./bootstrap.sh [OPTION]... 

Defaults for the options are specified in brackets.

Configuration:
  -h, --help                display this help and exit
  --with-bjam=BJAM          use existing Boost.Jam executable (bjam)
                            [automatically built]
  --with-toolset=TOOLSET    use specific Boost.Build toolset
                            [automatically detected]
  --show-libraries          show the set of libraries that require build
                            and installation steps (i.e., those libraries
                            that can be used with --with-libraries or
                            --without-libraries), then exit
  --with-libraries=list     build only a particular set of libraries,
                            describing using either a comma-separated list of
                            library names or "all"
                            [all]
  --without-libraries=list  build all libraries except the ones listed []
  --with-icu                enable Unicode/ICU support in Regex 
                            [automatically detected]
  --without-icu             disable Unicode/ICU support in Regex
  --with-icu=DIR            specify the root of the ICU library installation
                            and enable Unicode/ICU support in Regex
                            [automatically detected]
  --with-python=PYTHON      specify the Python executable [python]
  --with-python-root=DIR    specify the root of the Python installation
                            [automatically detected]
  --with-python-version=X.Y specify the Python version as X.Y
                            [automatically detected]

Installation directories:
  --prefix=PREFIX           install Boost into the given PREFIX
                            [/usr/local]
  --exec-prefix=EPREFIX     install Boost binaries into the given EPREFIX
                            [PREFIX]

More precise control over installation directories:
  --libdir=DIR              install libraries here [EPREFIX/lib]
  --includedir=DIR          install headers here [PREFIX/include]


To Be Continued...


References:



Building C++ application on Ubuntu with CMake, make and VSCode

This article shows how to set up building C++ project with CMake and make in VSCode on Ubuntu.

First make sure cmake and make are installed:

$ cmake --version
cmake version 3.10.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
Licence GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Let's assume we have a C++ project with following structure:

build/
src/main.cpp
CMakeLists.txt

build is an empty directory; this is where the build output will be located.

src/main.cpp:

#include <iostream>

int main() {
    std::cout << "main()" << std::endl;
    return 0;
}


CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)
project(cmake-demo)
set(SOURCE src/main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE})


In VSCode, press CTRL+SHIFT+P or go to View >> Command Palette, select Tasks: Configure Default Build Task and then Create tasks.json file from template and then Other.

VSCode - Configure Default Build Task
VSCode - Command Palette


This will create ./.vscode/tasks.json with a sample task:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "echo Hello"
        },
}

We can replace it with cmake and make toolchain:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "CMake && make",
            "options": {
                "cwd": "${workspaceFolder}/build"
            },
            "command": "cmake make -DCMAKE_BUILD_TYPE=Debug .. && make -j 4",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

To build a project press CTRL+SHIFT+B or go to Terminal >> Run Build Task.

We'd get the output like this:

> Executing task: cmake make -DCMAKE_BUILD_TYPE=Debug .. && make -j 4 <

-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxxxxxx/xx/xxx/cmake-demo/build
Scanning dependencies of target cmake-demo
[ 50%] Building CXX object CMakeFiles/cmake-demo.dir/src/main.cpp.o
[100%] Linking CXX executable cmake-demo
[100%] Built target cmake-demo

Terminal will be reused by tasks, press any key to close it.


To run the executable (build output):

$ ./build/cmake-demo 
main()

References:


What is a CMake generator? - Stack Overflow
Ubuntu Manpage: cmake-generators - CMake Generators Reference
cmake(1) — CMake 3.5.2 Documentation
Visual Studio Code Setup for Beginners using C++ and CMake
C++ Development using Visual Studio Code, CMake and LLDB
How to compile C++ code with VS Code, CMake and NMake - 40tude
GCC and Make - A Tutorial on how to compile, link and build C/C++ applications
c++ - How does CMake choose gcc and g++ for compiling? - Stack Overflow

Sunday, 2 February 2020

Debugging C++ program in VSCode on Linux

Let's assume we have VSCode running in Ubuntu 18.04 and the following project structure:

cpp-demo/
cpp-demo/main.cpp
cpp-demo/src/foo.cpp
cpp-demo/include/foo.hpp


Let's assume we want to name the build output cpp-demo and place it at project's root directory:

cpp-demo/cpp-demo


To build and debug it we need to have

cpp-demo/.vscode/tasks.json
cpp-demo/.vscode/launch.json


Building


tasks.json contains build instructions. From the main menu (CTRL+SHIFT+P), choose Tasks: Configure Default Build Task and then g++ build active file. This will create a /.vscode/tasks.json file and open it in the editor. A task will be created there and we need to edit it like this:


cpp-demo/.vscode/tasks.json:


{
    "tasks": [
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${workspaceFolder}/main.cpp",
                "${workspaceFolder}/src/*.cpp",
                "-I",
                "${workspaceFolder}/include",
                "-o",
                "${workspaceFolder}/cpp-demo"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

To run the build task defined in tasks.json, press Ctrl+Shift+B or from the main menu choose Tasks: Run Build Task. This will run g++ compiler and create the output binary. To run it, open a new terminal (in VSCode) and run:

./cpp-demo

For the full list of variables used in VSCode configuration files see Visual Studio Code Variables Reference and visual studio code - VSCode environment variables besides ${workspaceRoot} - Stack Overflow.


If we want g++ to have verbose output we can add to list of arguments:

"-v"

If we want linker to create map files (where we can see all mangled names of functions):

"-Xlinker",
"-Map=${workspaceFolder}/output.map",

Debugging


launch.json contains debugger settings.  From the main menu, choose Debug: Add Configuration... and then choose C++ (GDB/LLDB). You'll then see a dropdown for various predefined debugging configurations. Choose g++ build and debug active file. This creates a launch.json file and opens it in the editor. We need to edit it a bit e.g. to set correct name of the binary in program:

cpp-demo/.vscode/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}/cpp-demo",
            "args": [],
            "stopAtEntry": true,
            "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"
        }
    ]
}

Current working folder (the one opened in VSCode, cpp-demo in our case) is workspace so ${workspaceFolder} contains path to it.

To start debugging, place some breakpoints in source code, press F5 or from the main menu choose Debug: Start Debugging


References:


Get Started with C++ and Mingw-w64 in Visual Studio Code
Get Started with C++ and Windows Subsystem for Linux in Visual Studio Code
Configure launch.json for C/C++ debugging in Visual Studio Code
"g++" and "c++" compiler - Stack Overflow
c++ - What is the difference between g++ and gcc? - Stack Overflow
Compiling with g++