Using Yocto/ELBE SDK for application development
This site is under construction!
Root filesystems made by Yocto and ELBE can come with a SDK to build applications for the rootFS.
Installation
To install the SDK the following packets have to be installed on the machine:
- xz-utils
- file
- patchelf
Run the setup-script (e.g. setup-elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0.sh) as root to start the installation.
Using the SDK
The SDK consists of two parts:
- A folder with two sysroots
- "host": In this folder are the programms for the development host for using the SDK (e.g. compiler, debugger, ...).
- "target": This sysroot contains headers and libraries needed by the linker to build applications for the rootFS.
- A file with environment variables to setup the build environment (sourcing this file sets variables like ${CC} or ${LD})
Folowing are instructions how to use the SDK with different build-systems and IDEs (All examples using an ELBE toolchain installed at "opt/elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0"):
Makefiles
Open a shell and source the file with the environment variables:
user@machine:/<projectdir># source /opt/elbe-sdk-arm-linux-gnueabi-dhcom-buster-1.0/environment-setup-elbe-arm-linux-gnueabihf-dhcom-buster-1.0
Now you can use make to build applications in this shell session.
user@machine:/<projectdir># make
If you want to use another toolchain, you have to start a new shell session.
Important: Do not overwrite variables which were set by SDK in the makefile (or call make with '-e' to discard variables set in the makefile).
CMake
Setting up CMake to use the toolchain in the SDK is not much different than makefiles:
At first source the file with the environment variables inside a shell:
user@machine:/<projectdir># source /opt/elbe-sdk-arm-linux-gnueabi-dhcom-buster-1.0/environment-setup-elbe-arm-linux-gnueabihf-dhcom-buster-1.0
Now, for the remainder of this shell session, you can use CMake with this SDK:
user@machine:/<projectdir># cd build user@machine:/<projectdir>/build# cmake .. user@machine:/<projectdir>/build# cd .. user@machine:/<projectdir># cmake --build build
If you want to use another toolchain, you have to start a new shell session.
Qt-Creator
Start Qt Creator.
Now open the "Options"-window (Tools -> Options).
In the section "Build & Run" add in the "Compilers"-tab new compilers for C and C++ (Add -> GCC --> C / C++). Set the compiler path to the fitting executable in "/opt/elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0/sysroots/host/usr/bin/".
If the toolchain in the SDK includes Qt, switch to the "Qt Versions"-tab and add the qmake executable of the toolchain (usually in "/opt/elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0/sysroots/host/usr/bin/qt5/qmake").
For the debugger, change to the "Debuggers"-tab and add the gdb-multiarch executable of the toolchain (usually in "/opt/elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0/sysroots/host/usr/bin/gdb-multiarch").
If you want to deploy built software directly onto the embedded device, then change to the section "Devices" and add a new device. Select "Generic Linux Device" and set the IP-address, username and password.
Now change back to the section "Build & Run". In the tab "Kits" you have to add a new Kit for the toolchain. Set the compilers, debuggers, Qt and the device to these, which you have defined at the preceding steps. If the SDK does not include Qt you have to set Qt to "None" (like in the example).
Now you have to define the environment. Set the environment for the kit according to the environment setup file (but remove the "export" statements). If there are files inside the folders "/opt/elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0/sysroots/host/environment-setup.d/" or "/opt/elbe-sdk-arm-linux-gnueabihf-dhcom-buster-1.0/sysroots/target/environment-setup.d/", any environment variables which are set in those have also be included.
Now any project in Qt Creator can use the toolchain of the SDK if the kit is selected for the project. If you want to use another SDK-toolchain, you can switch the used kit for the project.
Eclipse
To use Eclipse with the SDK you have to start a shell and source the environment setup file and then open eclipse through that shell:
user@machine:~# source /opt/elbe-sdk-arm-linux-gnueabi-dhcom-buster-1.0/environment-setup-elbe-arm-linux-gnueabihf-dhcom-buster-1.0 user@machine:~# eclipse
When creating a new Eclipse project, use "Linux GCC" as the toolchain, the variables set by the environment setup are enough.
After creating the project open the project settings and go to the section "C/C++ Build -> Settings". Now go to "GCC C Compiler" and set the "Command" to "${CC}".
Now go to "GCC C Linker", change the "Command" to "${CC}" and add at "Command line pattern" between "${COMMAND}" and "${FLAGS}" "${LDFLAGS}"
Now go to "GCC Assembler" and change the "Command" to "${AS}".
The toolchain of the SDK con now be used by Eclipse as long Eclipse is not closed. If you want to a toolchain of another SDK you have to close Eclipse and source the environment setup of the other SDK and start Eclipse from that shell.
External Links
- Yocto SDK documentation
- Blog on configuring Qt Creator for Yocto SDK
- How-to for using the Yocto SDK with Eclipse - NOTE: The Yocto plugin for Eclipse mentioned at this site is no longer maintained (in 2020) and is not available on recent versions of Eclipse!