There are two general ways of building your own native application for the target: it can be built either manually, using the cross toolchain of the SDK, or integrated into the BSP, using Yocto and bitbake as a build system. Integrating the application into the BSP build process is the more complex way and useful only if you have modified the BSP and want to deploy a complete root file system image to the target anyway. For a single application, using the BSP in its original state as provided by SECO Northern Europe, the SDK is recommended to be used. The following sections describe how to build a simple Hello World! application using the SDK.
...
The installer will ask you if you want to install the SDK into a subfolder in /opt. Press Y for yes.
For more in-depth information, refer to the official Yocto documentation here.
...
Code Block |
---|
$ cd ~ $ mkdir myapp $ cd myapp |
Create the empty files main.cpp and Makefile in this directory:
Code Block |
---|
$ touch main.cpp Makefile |
Edit the contents of the main.cpp file as follows:
Code Block |
---|
#include <iostream> using namespace std; int main(int argc, char *argv[]) { cout << "Hello World!" << endl; return 0; } |
Edit the contents of the Makefile as follows:
Code Block |
---|
myapp: main.cpp $(CXX) $(CXXFLAGS) -o $@ $< $(STRIP) $@ clean: rm -f myapp *.o *~ *.bak |
...
Code Block |
---|
$ source /opt/guf/GUF-Yocto-rocko-12.5-0-IMX6GUF-sdk/environment-setup-imx6guf-guf-linux-gnueabi $ make |
in the myapp directory. The first line configures the current shell and sets the necessary environment variables. This needs to be done when shell is opened. In a new shell/terminal window or after a reboot you need to execute it again.
After a successful build, the myapp executable is created in the myapp directory. You can transfer this application to the target system’s /usr/bin directory using one of the ways described in chapter [Accessing the target system] and execute it from the device shell. It might be necessary to change the access rights of the executable first, so that all users are able to execute it.
...
Code Block |
---|
$ cd ~ $ mkdir myqtapp $ cd myqtapp |
Create the empty files main.cpp and myqtapp.pro.
Code Block |
---|
$ touch main.cpp myqtapp.pro |
Edit the contents of the file main.cpp as follows:
Code Block |
---|
#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); app.setOverrideCursor(Qt::BlankCursor); QPushButton hello("Hello World!"); hello.setWindowFlags(Qt::FramelessWindowHint); hello.resize(800, 480); hello.show(); return app.exec(); } |
Edit the contents of the file myqtapp.pro as follows:
Code Block |
---|
TEMPLATE = app TARGET = myqtapp QT = core gui widgets SOURCES += \ main.cpp |
After setting up the build environment, execute the following command to create a Makefile and build the binary in the myqtapp directory:
Code Block |
---|
$ qmake myqtapp.pro $ make |
Now, there is the myqtapp executable in the myqtapp directory. You can transfer this application to the target system’s /usr/bin directory and run it from the device shell.