Yocto Programming with CodeBlocks: Difference between revisions
No edit summary |
|||
Line 114: | Line 114: | ||
[[File:CodeBlock-OtherLinkerOptions.jpg]] | [[File:CodeBlock-OtherLinkerOptions.jpg]] | ||
= Create the reference helper scripts to deploy and debug with Code::Blocks = | |||
Here, we will create the following files: | |||
{| class="wikitable" | |||
|- | |||
|'''/home/user/bin/var-sdk.conf''' || configuration file hosting target parameters | |||
|- | |||
|'''/home/user/bin/var-sdk-deploy.sh''' || script to automate binary deploy | |||
|- | |||
|'''/home/user/bin/var-sdk-debug.sh''' || script to automate binary debug | |||
|} | |||
Create the file '''/home/user/bin/var-sdk.conf''' using the right IP address of the board: | |||
<syntaxhighlight lang="bash"> | |||
TARGET_DIR="/home/root" | |||
TARGET_IP="192.168.73.165" | |||
TARGET_PORT="3000" | |||
SSH_OPTIONS="-oStrictHostKeyChecking=no" | |||
</syntaxhighlight> | |||
Create the file '''/home/user/bin/var-sdk-deploy.sh''': | |||
<syntaxhighlight lang="bash"> | |||
#!/bin/bash | |||
readonly PROGRAM="$1" | |||
PROGRAMNAME="$(basename $PROGRAM)" | |||
. /home/user/bin/var-sdk.conf | |||
echo "Deploying to target" | |||
# prevent "Host key verification failed" | |||
ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${TARGET_IP}" | |||
# delete old binary | |||
ssh ${SSH_OPTIONS} root@${TARGET_IP} "sh -c 'rm -rf ${TARGET_DIR}/${PROGRAMNAME}'" | |||
# send the program to the target | |||
scp ${PROGRAM} root@${TARGET_IP}:${TARGET_DIR}/${PROGRAMNAME} | |||
</syntaxhighlight> | |||
Create the file '''/home/user/bin/var-sdk-debug.sh''': | |||
<syntaxhighlight lang="bash"> | |||
readonly PROGRAM="$1" | |||
PROGRAMNAME="$(basename $PROGRAM)" | |||
. /home/user/bin/var-sdk.conf | |||
echo "Starting GDB Server on Target" | |||
# kill gdbserver on target | |||
ssh ${SSH_OPTIONS} root@${TARGET_IP} "sh -c '/usr/bin/killall -q gdbserver'" | |||
# start gdbserver on target and fork | |||
ssh ${SSH_OPTIONS} -t root@${TARGET_IP} "sh -c 'gdbserver localhost:${TARGET_PORT} ${TARGET_DIR}/${PROGRAMNAME}'" & | |||
</syntaxhighlight> | |||
Finally make all of them executable: | |||
$ chmod +x /home/user/bin/var-sdk* | |||
= Create a sample project with Code::Blocks = | = Create a sample project with Code::Blocks = |
Revision as of 19:01, 17 January 2022
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
In the "Debugger Settings" window, select "GDB/CDB debugger" and click on "Create Config"
In the "Create config" window, enter the new debugger's name and press OK
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
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
In the "Global Compiler Settings" window, click on Copy
In the "Add new compiler" window, enter the new compiler's name and press OK
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
Click on the "Compiler settings" tab, then on the "Other compiler options" tab, and finally add the right options.
The default settings is
--sysroot=/opt/fslc-xwayland/3.1/sysroots/aarch64-fslc-linux
Click on the "Linker settings" tab, then on the "Other linker options" tab, and finally add the right options.
As above, the default settings is
--sysroot=/opt/fslc-xwayland/3.1/sysroots/aarch64-fslc-linux
Create the reference helper scripts to deploy and debug with Code::Blocks
Here, we will create the following files:
/home/user/bin/var-sdk.conf | configuration file hosting target parameters |
/home/user/bin/var-sdk-deploy.sh | script to automate binary deploy |
/home/user/bin/var-sdk-debug.sh | script to automate binary debug |
Create the file /home/user/bin/var-sdk.conf using the right IP address of the board:
TARGET_DIR="/home/root"
TARGET_IP="192.168.73.165"
TARGET_PORT="3000"
SSH_OPTIONS="-oStrictHostKeyChecking=no"
Create the file /home/user/bin/var-sdk-deploy.sh:
#!/bin/bash
readonly PROGRAM="$1"
PROGRAMNAME="$(basename $PROGRAM)"
. /home/user/bin/var-sdk.conf
echo "Deploying to target"
# prevent "Host key verification failed"
ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${TARGET_IP}"
# delete old binary
ssh ${SSH_OPTIONS} root@${TARGET_IP} "sh -c 'rm -rf ${TARGET_DIR}/${PROGRAMNAME}'"
# send the program to the target
scp ${PROGRAM} root@${TARGET_IP}:${TARGET_DIR}/${PROGRAMNAME}
Create the file /home/user/bin/var-sdk-debug.sh:
readonly PROGRAM="$1"
PROGRAMNAME="$(basename $PROGRAM)"
. /home/user/bin/var-sdk.conf
echo "Starting GDB Server on Target"
# kill gdbserver on target
ssh ${SSH_OPTIONS} root@${TARGET_IP} "sh -c '/usr/bin/killall -q gdbserver'"
# start gdbserver on target and fork
ssh ${SSH_OPTIONS} -t root@${TARGET_IP} "sh -c 'gdbserver localhost:${TARGET_PORT} ${TARGET_DIR}/${PROGRAMNAME}'" &
Finally make all of them executable:
$ chmod +x /home/user/bin/var-sdk*
Create a sample project with Code::Blocks
From the Menu, click on New and Project
In the "New from template" window, select "Console application" and click on Go.
Unless you prefer changing something, click Next in the Welcome and Language windows
Populate the Project window according your needs and press Next.
Select from the drop-down list the compiler configured in the previous section and press Finish.
A sample HelloWorld project will show up in the IDE
Configure the project
From the previous view, right click on the project name and then click on Properties
In the "Project/targets option" windows, select Debug in the "Build targets" and then click on the "Build options"