Using Yocto/ELBE SDK for application development: Difference between revisions

From Wiki-DB
Jump to navigationJump to search
Added CMake and Qt Creator
Added section about Eclipse
Line 80: Line 80:


[[File:QtCreatorEnv.png|1311px]]
[[File:QtCreatorEnv.png|1311px]]


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.
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 ===
=== 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:
<nowiki>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</nowiki>
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}".
[[File:EclipseGCC.png]]
Now go to "GCC C Linker", change the "Command" to "${CC}" and add at "Command line pattern" between "${COMMAND}" and "${FLAGS}" "${LDFLAGS}"
[[File:EclipseLinker.png]]
Now go to "GCC Assembler" and change the "Command" to "${AS}".
[[File:EclipseAs.png]]
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.
<div class="toccolours mw-collapsible mw-collapsed" style="overflow:auto;">
<div style="font-weight:bold;">Linking against libraries of the SDK</div>
<div class="mw-collapsible-content">
If you want to link against libraries of the SDK change to subitem "Libraries" of the "GCC C Linker" settings. There you can add the name auf the library (without the prefix "lib"). The screenshot of the example shows the mosquitto library (libmosquitto) for sending and receiving MQTT messages.
[[File:EclipseLib.png]]
</div></div>


==External Links==
==External Links==

Revision as of 11:31, 22 June 2020

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/".

Example configuration for the compiler of the SDK
Example configuration for the compiler of the SDK

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.

Linking against libraries of the SDK

If you want to link against libraries of the SDK change to subitem "Libraries" of the "GCC C Linker" settings. There you can add the name auf the library (without the prefix "lib"). The screenshot of the example shows the mosquitto library (libmosquitto) for sending and receiving MQTT messages.

External Links