In my project I call gtk_builder_add_from_file function to load an xml file with the ui objects designed with Glade previously. So, I have my binary program and (in the same folder) the xml file.
What is the best way to pack all into a single executable? should I use a self-extracting script? or there is something else to compile all together?
Thanks to all
You can use the
GResourceAPI available in GIO. GResources work by defining the assets you wish to ship with your application inside an XML file, similar to this:Take note of the
prefixattribute, because it will be used later.Once you've added your assets, you use the
glib-compile-resourcesbinary shipped by GLib to generate a C file that includes all your assets, encoded as byte arrays. The generated code will also use the global constructor functionality exposed by various compilers so that the resources are loaded once your application is loaded (and beforemainis called), or, in case of a shared object, once the library is loaded by the linker. An example ofglib-compiler-resourcesinvocation in a Makefile is:Then you have to add the
your-app-resources.cto your build.In order to access your assets you should use the
from_resource()function that is exposed in various classes; for instance, to load a UI description inGtkBuilder, you should usegtk_builder_add_from_resource(). The path used is a combination of theprefixyou defined in the GResource XML file and the file name, e.g.:/com/example/YourApp/your-app.ui. You can also use theresource://URI when loading from aGFile.You can find more information on the GResources API reference page.