Yocto Programming with CodeBlocks: Difference between revisions

From Variscite Wiki
No edit summary
No edit summary
Line 44: Line 44:


Changes may be required if you installed the toolchain in a different path or you used different distro settings.
Changes may be required if you installed the toolchain in a different path or you used different distro settings.
== Configure the debugger ==


From the Menu, click on Settings and Debugger
From the Menu, click on Settings and Debugger
Line 64: Line 66:


[[File:CodeBlock-DebuggerExecutable.jpg]]
[[File:CodeBlock-DebuggerExecutable.jpg]]
== Configure the compiler ==
The next steps depends on the previous section: here we assume the debugger is already configured.


From the Menu, click on Settings and Compiler
From the Menu, click on Settings and Compiler

Revision as of 22:52, 16 January 2022

DART-MX8M-MINI - Yocto Programming with Code::Blocks

Code::Blocks is a free C/C++ IDE built around a plugin framework, designed to be very extensible and fully configurable.

This guide demonstrates how to create and debug a C++ application using Code::Blocks on the DART-MX8M-MINI.


Create your rootfs with Code::Blocks debug support

Debugging with Code::Blocks requires your preferred SSH server (openssh, dropbear, etc), gdb, and gdbserver installed on the target device. Append the following to the conf/local.conf file in your Yocto build directory:

EXTRA_IMAGE_FEATURES = " \
    tools-debug \
    ssh-server-dropbear \
    "

Now bitbake your image.

Setup Host Computer Environment

Please follow the steps below to prepare a fresh Ubuntu 20.04 installation for Code::Blocks debugging:

Install Dependencies

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

Install Code::Blocks

$ sudo apt install codeblocks codeblocks-contrib

Install Yocto Toolchain

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

Configure Code::Blocks

This section will provide defaults path, assuming you followed the default instruction in Variscite's Yocto Toolchain installation guide.

Changes may be required if you installed the toolchain in a different path or you used different distro settings.

Configure the debugger

From the Menu, click on Settings and Debugger

CodeBlock-MenuSettingsDebugger.jpg

In the "Debugger Settings" window, select "GDB/CDB debugger" and click on "Create Config"

CodeBlock-DebuggerSettings.jpg

In the "Create config" window, enter the new debugger's name and press OK

CodeBlock-CreateDebuggerConfig.jpg

Select in the right pane the new configuration, populate the "Executables path" fields and press OK.

The default path is

/opt/fslc-xwayland/3.1/sysroots/x86_64-fslcsdk-linux/usr/bin/aarch64-fslc-linux/aarch64-fslc-linux-gdb

CodeBlock-DebuggerExecutable.jpg

Configure the compiler

The next steps depends on the previous section: here we assume the debugger is already configured.

From the Menu, click on Settings and Compiler

CodeBlock-MenuSettingsCompiler.jpg

In the "Global Compiler Settings" window, click on Copy

CodeBlock-GlobalCompilerSettings.jpg

In the "Add new compiler" window, enter the new compiler's name and press OK

CodeBlock-AddNewCompiler.jpg

A popup windows will remind you to update the "Toolchain executables" page, just press OK.

Click on the "Toolchain executables" tab and populate the fields according your Yocto toolchain.

For the Debugger, in the drop-down list you should select the one created above.

The default settings are

  • Compiler's installation directory: /opt/fslc-xwayland/3.1/sysroots/x86_64-fslcsdk-linux/usr/bin/aarch64-fslc-linux
  • C compiler: aarch64-fslc-linux-gcc
  • C++ compiler: aarch64-fslc-linux-g++
  • Linker for dynamic libs: aarch64-fslc-linux-g++
  • Linker for static libs: aarch64-fslc-linux-ar
  • Debugger: GDB/CDB debugger: Variscite GDB
  • Resource compiler: <empty>
  • Make program: make

CodeBlock-ToolchainExecutables.jpg

Click on the "Additional Paths" tab and add a new directory, matching the Compiler's installation directory:

/opt/fslc-xwayland/3.1/sysroots/x86_64-fslcsdk-linux/usr/bin/aarch64-fslc-linux

then press OK.

CodeBlock-AdditionalPaths.jpg

Code::Blocks is not able to detect Yocto toolchain enviroment settings, that must manually added.

To optimize the compilation, click on the "Compiler settings" tab and then on the "Other compiler options" tab, finally add the right options.

CodeBlock-OtherCompilerOptions.jpg

The default settings is

-mcpu=cortex-a53+crc+crypto -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/fslc-xwayland/3.1/sysroots/aarch64-fslc-linux

If unsure, you can get the right options running

$ source /opt/fslc-xwayland/3.1/environment-setup-aarch64-fslc-linux
$ export LDFLAGS= $ echo $CXX | cut -d' ' -f2-