codekiddy
codekiddy

Reputation: 6137

Can't execute built gtkmm program when it uses a glade file

When I build a gtkmm application that uses (loads) .glade file with Gtk::Builder, and then double clicking on the application (in file explorer) it won't show the UI, how ever when launching the same application from the shell is runs just fine and shows the interface.

also I tried to crate the exactly same app without support of glade and it runs just fine when double clicking the app in file explorer (it shows UI).

Is there any trick when building apps with glade or what do I need to do?

snapshot of main.cpp

int main(int argc, char *argv[])
{
    Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "freme.ccp");
    Glib::RefPtr<Gtk::Builder> pBuilder = Gtk::Builder::create_from_file("frame.glade");

    frame* pFrame = nullptr;
    pBuilder->get_widget_derived("AppWindow", pFrame);

    app->run(*pFrame);

    delete pFrame;
    return 0;
}

the frame.glade file is in the same directory as sources and output application.

Upvotes: 0

Views: 432

Answers (1)

user3814483
user3814483

Reputation: 312

One way to avoid such issues is to modify your build scripts to generate object code from your glade files and link these symbols into your executable. For instance, you can create a build target for the glade files (I'm assuming you're using make and makefiles)

gladetarget:
        ld  -r -b binary -o somefile.o somefile.glade

Then you'd modify the build target for your main executable to build this target first, and include the object file:

main: gladetarget
        g++ main.cc somefile.o -o myprogram 

(I've omitted the GTK flags in the above, example, but you get the idea). Then you'd define an external variable in your code and point Gtk::Builder to it:

extern char _binary_somefile_glade_start[];
...
Gtk::Builder::create_from_string(_binary_somefile_glade_start);

Note that you can get the symbol names in somefile.o using the nm command. Obviously, this method has some drawbacks. Namely, you have to re-compile your code if you make a simple GUI change. On the flip side, it prevents people from tinkering with your GUI.

Upvotes: 1

Related Questions