Yocto Programming with VSCode

From Variscite Wiki
Revision as of 17:24, 13 July 2021 by Nate (talk | contribs)
VAR-SOM-MX8M-NANO - Yocto Programming with Visual Studio Code

This guide describes how to use Visual Studio Code (VSCode) to develop and debug applications on the VAR-SOM-MX8M-NANO.

C/C++ Application Development and Debugging using CMake

VSCode has C/C++ and CMake extensions that make it easy to develop, build, and debug C/C++ applications. Microsoft has a detailed guide for getting started with CMake on Linux.

This section will extend Microsoft's guide to support cross compiling for Variscite IMX8 Yocto images.

Setup Host Computer Environment

This guide is tested using a fresh Ubuntu 20.04 installation.

Install Dependencies

$ sudo apt-get -y update
$ sudo apt-get -y install build-essential gdb gdb-multiarch cmake

Install VSCode

$ sudo snap install --classic code

Install VSCode Extensions

VSCode has a graphical interface for installing and managing extensions. To learn more, please see Using extensions in Visual Studio Code

For this guide, we will install the required extensions using the command line:

$ code --install-extension ms-vscode.cmake-tools
$ code --install-extension ms-vscode.cpptools

Install Yocto Toolchain

A toolchain is necessary for cross compiling applications. To install the toolchain, follow Variscite's Yocto Toolchain installation guide.

Build a "Hello World" CMake project using VSCode

Create an empty project directory and open VSCode:

$ mkdir ~/var-hello-world
$ cd ~/var-hello-world
$ source /opt/fsl-imx-xwayland/5.4-zeus/environment-setup-aarch64-poky-linux
$ code .

Open the VSCode Command Palette (Ctrl+Shift+P) and run the CMake: Quick Start command.

Enter a project name and select 'Create an Executable'. This will create a new "Hello World" CMake project.

Next, select a kit informing VSCode where the toolchain compiler is. Open the Command Palette (Ctrl+Shift+P) and run the CMake: Select a kit command and select aarch64-poky-linux

Open the Command Palette (Ctrl+Shift+P) and run the CMake: Build command

Deploy the binary to the target device:

$ scp build/hello root@192.168.0.174:

Run the binary on the target device:

# ./hello 
Hello, world!