This service is available only in Japanese-language.
2020年4月9日、10日に実演したSDKを使用したアプリケーション構築の内容です。
1) native 構築の確認
$ gcc -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-3.0`
2) 構築されたプログラムの動作確認
$ ./helloworld
3) 構築環境(pkg-config)の確認
$ pkg-config --cflags --libs gtk+-3.0
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircore -I/usr/include/mircookie -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
4) cross 構築環境の設定
$ source /opt/fsl-imx-xwayland/4.14-sumo/environment-setup-aarch64-poky-linux
5) 設定された環境の確認
$ printenv CC
aarch64-poky-linux-gcc --sysroot=/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux
CC環境変数に、クロスコンパイラであるaarch64-poky-linux-gcc と、/usr/include や /usr/lib にある
ことを期待するファイルを検索する際の起点をクロス構築用に置き換える sysroot が指定されています。
6) cross 構築
$ $CC -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-3.0`
native構築で、gcc と指定した分を $CC に置き換えるだけで、arm 向けの構築が可能となります。
7) 構築環境(pkg-config)の確認
$ pkg-config --cflags --libs gtk+-3.0
-DLINUX -DEGL_API_FB -DWL_EGL_PLATFORM -pthread -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/gtk-3.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/at-spi2-atk/2.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/at-spi-2.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/dbus-1.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/lib/dbus-1.0/include -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/gtk-3.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/gio-unix-2.0/ -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/cairo -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/libdrm -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/pango-1.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/harfbuzz -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/pango-1.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/atk-1.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/cairo -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/pixman-1 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/freetype2 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/libpng16 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/gdk-pixbuf-2.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/libpng16 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/include/glib-2.0 -I/opt/fsl-imx-xwayland/4.14-sumo/sysroots/aarch64-poky-linux/usr/lib/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
付録
ソースコード helloworld.c
=============================================================================================
1 #include <gtk/gtk.h>
2
3 static void
4 print_hello (GtkWidget *widget,
5 gpointer data)
6 {
7 g_print ("Hello World\n");
8 }
9
10 static void
11 activate (GtkApplication *app,gcc -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-3.0`
12 gpointer user_data)
13 {
14 GtkWidget *window;
15 GtkWidget *button;
16 GtkWidget *button_box;
17
18 window = gtk_application_window_new (app);
19 gtk_window_set_title (GTK_WINDOW (window), "Window");
20 gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
21
22 button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
23 gtk_container_add (GTK_CONTAINER (window), button_box);
24
25 button = gtk_button_new_with_label ("Hello World");
26 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
27 g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
28 gtk_container_add (GTK_CONTAINER (button_box), button);
29
30 gtk_widget_show_all (window);
31 }
32
33 int
34 main (int argc,
35 char **argv)
36 {
37 GtkApplication *app;
38 int status;
39
40 app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
41 g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
42 status = g_application_run (G_APPLICATION (app), argc, argv);
43 g_object_unref (app);
44
45 return status;
46 }
=============================================================================================