Bitbake gtk 3 c code do_install error

Hi,
I am trying to bitbake nsgtk a c file of which the content is -


                         nsgtk.c

#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;

window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), “Window”);
gtk_window_set_default_size (GTK_WINDOW (window), 800, 480);
gtk_widget_show_all (window);
}

int
main (int argc, char **argv)
{
GtkApplication *app;
int status;

app = gtk_application_new (“org.gtk.example”, G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, “activate”, G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}


My meta-customer directory structure is -
ansij@mansij-Inspiron-N5050:~/oe-core/layers/meta-customer$ tree
.
├── COPYING.MIT
├── README
├── conf
│ └── layer.conf
├── recipes-customer
│ ├── hello-world
│ │ ├── hello-world
│ │ │ └── hello-world.c
│ │ └── hello-world_1.0.0.bb
│ ├── iptx
│ │ ├── iptx
│ │ │ └── iptx.c
│ │ └── iptx_1.0.0.bb
│ └── nsgtk
│ ├── nsgtk
│ │ └── nsgtk.c
│ └── nsgtk_1.0.0.bb
└── recipes-example
└── example
└── example_0.1.bb


My nsgtk_1.0.0.bb file is -


Package summary

SUMMARY = “nsgtk”

License, for example MIT

LICENSE = “MIT”

License checksum file is always required

LIC_FILES_CHKSUM = “file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302”

nsgtk.c from local file

SRC_URI = “file://nsgtk.c”

Change source directory to workdirectory where nsgtk.c is

S = “${WORKDIR}”

DEPENDS += “gtk+3”

Process permissions, Working directory, file creation mask, Special variables, and Open files

inherit pkgconfig

Set LDFLAGS options provided by the build system

TARGET_CC_ARCH += “${LDFLAGS}”

Compile nsgtk.c from sources, no Makefile

do_compile() {
${CC} -Wall ${LDFLAGS} nsgtk.c -o hello_gtk pkg-config --cflags --libs gtk+-3.0
}

Install binary to final directory /usr/bin

do_install() {
install -d ${D}${bindir}
install -m 755 ${S}/nsgtk ${D}${bindir}/
}


bitbake nsgtk gives following error -
DEBUG: Executing shell function do_install
| install: cannot stat ‘/home/mansij/oe-core/build/tmp/work/armv7at2hf-neon-tdx-linux-gnueabi/nsgtk/1.0.0/nsgtk’: No such file or directory
| WARNING: exit code 1 from a shell command.
ERROR: Task (/home/mansij/oe-core/build/…/layers/meta-customer/recipes-customer/nsgtk/nsgtk_1.0.0.bb:do_install) failed with exit code ‘1’
NOTE: Tasks Summary: Attempted 4355 tasks of which 4345 didn’t need to be rerun and 1 failed.
NOTE: Writing buildhistory
NOTE: Writing buildhistory took: 17 seconds

Summary: 1 task failed:
/home/mansij/oe-core/build/…/layers/meta-customer/recipes-customer/nsgtk/nsgtk_1.0.0.bb:do_install
Summary: There were 2 WARNING messages.
Summary: There was 1 ERROR message, returning a non-zero exit code.


Can you help?
Thanks,
Mansij

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Mansij,

Thank you for reaching out with your question. The error you’re encountering is due to a mismatch between the name of the binary file generated during the compilation step and the name expected during the installation step in your Yocto recipe.

In your nsgtk_1.0.0.bb file, the do_compile function compiles the nsgtk.c file into a binary named hello_gtk:

do_compile() {
    ${CC} -Wall ${LDFLAGS} nsgtk.c -o hello_gtk `pkg-config --cflags --libs gtk+-3.0`
}

However, in the do_install function, you are trying to install a binary named nsgtk:

do_install() {
    install -d ${D}${bindir}
    install -m 755 ${S}/nsgtk ${D}${bindir}/
}

To resolve this issue, you need to ensure that the binary name in the do_install step matches the name of the compiled binary. You can do this by changing the do_install function to:

do_install() {
    install -d ${D}${bindir}
    install -m 755 ${S}/hello_gtk ${D}${bindir}/
}

This change should resolve the error by correctly referencing the compiled binary hello_gtk during the installation step. After making this change, try running bitbake nsgtk again.

I hope this helps! If you have any more questions, feel free to ask.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

What Linux OS do I need to use to create and use GTK application?.

Thank you ToradexAI. This worked. Looks like I have to build an AI to do my code review.

Dear @mansijc,

Thank you for trying out the @ToradexAI solution. I am glad the generated reply was able to help you out. If this is indeed the solution to your problem, could you tag the AI solution as “solves the problem”?

Best regards,
Collin