Yocto Recipe for a GTK Application
Say, you have a GTK Application and you want this application to be compiled and installed on the target machine.
hello_gtk.c
To compile on your own machine you run the following command.
$ gcc files/hello_gtk.c -o hello_gtk `pkg-config --cflags --libs gtk+-3.0`
hello_gtk.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtk/gtk.h> | |
int main (int argc, char *argv[]) | |
{ | |
GtkWidget *window;// GtkWidget is the storage type for widgets | |
gtk_init (&argc, &argv);// This is called in all GTK applications. Arguments are parsed | |
//from the command line and are returned to the application. | |
window=gtk_window_new(GTK_WINDOW_TOPLEVEL); //creating a new window. | |
gtk_widget_show(window); | |
gtk_main (); //All GTK applications must have a gtk_main(). Control ends here | |
//and waits for an event to occur (like a key press or mouse event). | |
return 0; | |
} |
$ gcc files/hello_gtk.c -o hello_gtk `pkg-config --cflags --libs gtk+-3.0`
Steps to achieve the same on your Yocto Image:
1. Create a folder named 'gtk-hello' in your own layer : mkdir gtk-hello
2. Create a recipe named 'gtk-hello_1.0.bb' in the newly created folder with the following contents:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DESCRIPTION = "Simple GTK 3.0 Hello World Application" | |
LICENSE = "CLOSED" | |
SRC_URI = "file://hello_gtk.c" | |
S = "${WORKDIR}" | |
DEPENDS = "gtk+3" | |
inherit pkgconfig | |
do_compile() { | |
${CC} ${LDFLAGS} hello_gtk.c -o hello_gtk `pkg-config --cflags --libs gtk+-3.0` | |
} | |
do_install() { | |
install -d ${D}${bindir} | |
install -m 0755 hello_gtk ${D}${bindir} | |
} | |
FILES_${PN} += "${bindir}/hello_gtk" |
3. Create a folder inside 'gtk-hello' named files and copy the 'hello_gtk.c' file into it
4. To include this add IMAGE_INSTALL += "gtk-hello" into local.conf or your machine configuration
Comments
Post a Comment