Yocto Programming with VSCode: Difference between revisions

From Variscite Wiki
(Add vscode cmake build steps)
 
No edit summary
Line 13: Line 13:


== Setup Host Computer Environment ==
== 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 ===
=== Install VSCode ===
Line 20: Line 27:
=== Install VSCode Extensions ===
=== Install VSCode Extensions ===


To learn how to install and manage extensions using VSCode, please review [https://code.visualstudio.com/docs/introvideos/extend Using extensions in Visual Studio Code]
VSCode has a graphical interface for installing and managing extensions. To learn more, please see [https://code.visualstudio.com/docs/introvideos/extend Using extensions in Visual Studio Code]


Instead, we will install the extensions using the command line:
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.cmake-tools
  $ code --install-extension ms-vscode.cpptools
  $ code --install-extension ms-vscode.cpptools
=== Install required dependencies (tested with Ubuntu 20.04):===
$ sudo apt update
$ sudo apt-get install build-essential gdb cmake
$ sudo snap install --classic code


=== Install Yocto Toolchain ===
=== Install Yocto Toolchain ===


To install the toolchain, follow {{Varlink2|Yocto Toolchain installation|{{#var:RELEASE_LINK}}}} guide.
A toolchain is necessary for cross compiling applications. To install the toolchain, follow Variscite's {{Varlink2|Yocto Toolchain installation|{{#var:RELEASE_LINK}}}} guide.


== Build a "Hello World" CMake project using VSCode ==
== Build a "Hello World" CMake project using VSCode ==

Revision as of 17:24, 13 July 2021

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!