User Guide

  • 2021.2
  • 04/12/2021
  • Public Content

Developing a Visual Studio Code* Project for SSH Development on Windows Subsystem for Linux*

The following procedure will use a Remote Host connection enabling you to edit and debug your code using the Windows Subsystem for Linux* (WSL).

Prerequisites

It is not necessary to install VSCode on your Linux target that is running on WSL. VSCode is only needed on your Windows development system. The Linux installed on WSL does not require a GUI in order to be used for Linux development.

Set oneAPI Environment Variables on the WSL Target Linux

In order to perform development on your remote WSL target, you must install (at minimum) the Intel® oneAPI Base Toolkit (Base Kit) and configure the oneAPI development environment variables on the WSL target Linux. The recommended installation method is Installing via Linux* Package Managers.
  1. Open a WSL terminal and install the Base Kit on to that target Linux system using the appropriate Linux package manager.
    To get started, you need to install only the Base Kit on your WSL target; you can install additional oneAPI toolkits either now or at a later time.
  2. Configure your WSL Linux target so that the oneAPI development environment script (
    setvars.sh
    ) runs when VS Code initiates a connection.
    Visual Studio Code does not currently provide a mechanism to automatically run scripts on your remote Linux target when it interacts with the WSL system (for example, running
    setvars.sh
    automatically). There are a variety of ways to get around this issue, only one of which is presented here. See the Bash Startup Files man page for more options.
    Add the following shell script lines to your remote Linux system's
    /etc/profile
    script. This location (or in an
    /etc/profile.d/
    script) will ensure that all users of your WSL target development system will run the
    setvars.sh
    environment script when they connect using Visual Studio Code:
    . /opt/intel/oneapi/setvars.sh &>/dev/null
    The above assumes that you have installed your oneAPI toolkits on the WSL system in the default "root/sudo" installation location (
    /opt/intel/oneapi/
    ). If you have installed the oneAPI tools in a different location on your remote Linux system, you will have to adjust the path to
    setvars.sh
    .
    See Configure Your CPU or GPU System for more details regarding configuration of the oneAPI environment on a Linux system.

Configure Visual Studio Code on Your Local Host

You must install the VS Code "Remote - WSL" extension into your local copy of VS Code. This extension facilitates development on the WSL* system.
  1. Install the
    Remote - WSL
    extension by Microsoft. Click the
    Extensions
    icon and search for "remote wsl" in the search bar.
  2. Click
    install
    . After installation, you see
    Remote – WSL
    in the
    Installed Extensions
    list.

Connect to Your WSL Linux System

See the Visual Studio Code Remote Development in WSL documentation for detailed instructions, requirements, and additional information.
  1. Open a WSL terminal for your desired Linux distribution. From within the terminal, invoke VS Code from the command line to start a local instance connected to WSL.
    user@host:~$ code
  2. A new VS Code window opens and is connected to the WSL system.
  3. Once connected, add the
    C/C++ extension
    to the VS Code instance. This extension is required to debug a remote session using the VS Code debug interface.

Create a Blank Project

  1. Click
    File
    New File
    to open a blank file in Visual Studio Code (VS Code).
  2. Once you have completed writing code, you can save it as a file or save it as a workspace. For more information on workspaces, see the Visual Studio Code Get Started Guide.
  3. To run the code, click
    Run
    Run without Debugging
    .
  4. Select C++ as the language. The code will run.

Import an Existing Project

  1. Click
    File
    Open File
    or
    File
    Open Workspace
    to open an existing project in Visual Studio Code (VS Code).
  2. Once you have completed writing code, you can save it as a file or save it as a workspace. For more information on workspaces, see the Visual Studio Code Get Started Guide.
  3. To run the code, click
    Run
    Run without Debugging
    .
  4. Select C++ as the language. The code will run.

Try Debugging (CPU Only) (Preview)

Intel® Distribution for GDB* does not currently support VS Code. You can use upstream gdb to debug.
This section assumes that you can build your sample and have installed the Microsoft VS Code C/C++ Extension. The C/C++ extension is required to configure the oneAPI C/C++ debugger.
The Intel
®
oneAPI Base Toolkit
includes a special version of GNU* GDB (
gdb-oneapi
) designed to support oneAPI C/C++ applications. To debug your DPC++ application using this special debugger, you will need to make changes to the
.vscode/launch.json
configuration file.
  1. Go to
    Debug
    Open Configurations
    , and open the
    launch.json
    configuration settings.
    If you are prompted to select a debug environment, choose
    C++ (GDB/LLDB)
    .
    Screenshot showing command pallet prompting for debugger
  2. Copy the code shown below into your
    launch.json
    file, and replace the
    "program":
    property's value with the path to your project's executable (that is, the application that you are going to debug).
    If VS Code doesn't recognize the application name, you may have to insert the full path and file name into the
    launch.json
    file's
    "program":
    property.
  3. Add
    gdb-oneapi
    to your
    launch.json
    configuration's
    "miDebuggerPath":
    property.
    The
    gdb-oneapi
    application should have been added to your path when you ran
    setvars.sh
    to configure the oneAPI development environment, prior to starting VS Code. If you prefer, you can specify the full path and filename to the
    gdb-oneapi
    application in your
    launch.json
    file.
  4. In some configurations, GDB may not be compatible with VS Code. If this happens, add the environment variable to disable `gdb-oneapi` support for GPU autolaunch. This can either be done in the environment prior to launching VS Code, or within the launch.json:
    export INTELGT_AUTO_ATTACH_DISABLE=1
    { "version":"0.2.0", "configurations":[ { "name":"(gdb) Launch", "type":"cppdbg", "request":"launch", "program":"${workspaceFolder}/build/array-transform", "args":[ "cpu" ], "stopAtEntry":false, "cwd":"${workspaceFolder}", "environment":[ { "name":"INTELGT_AUTO_ATTACH_DISABLE", "value":"1" } ], "externalConsole":false, "MIMode":"gdb", "miDebuggerPath":"gdb-oneapi", "setupCommands":[ { "description":"Enable pretty-printing for gdb", "text":"-enable-pretty-printing", "ignoreFailures":true } ] } ] }
  5. Bring up the debug view by selecting the
    Run
    icon in the
    Activity Bar
    . You can also use the keyboard shortcut (
    Ctrl+Shift+D
    ).
  6. Start the run and debug session by clicking the green
    DEBUG AND RUN
    icon, or go to
    Run
    Start Debugging
    (
    F5
    ).
    Screenshot showing VS Code recommended extension installation popup

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.