Resources generated by `glib-compile-resources` not found at runtime

Hi :wave: I would really appreciate some thoughts about what is going on with this error message.

I made a minimal reproducible example using the code samples from the gtkmm-4-8 book I won’t mention the chapter because that will change depending on the version

The steps to reproduce this is as follow:

  1. I’m defining a gresource.xml file that bundles the resources I need

  2. I execute glib-compile-resources (see Makefile of the MRE for more detailed insight)

  3. I then move the generated C header and source

  4. I compile my C++ project including those files

  5. I build, compile, and run. The app hits the error immediately because the interface is needed to build and display the window

I have tried different approaches such us

  • running/testing on different versions of Gtkmm
  • define the string to the resource with and without a lead forward slash
  • define the string to the resource as “resource:/// …”
  • get an instance of Gtk::Builder and call add_from_resource instead of the static method. Same result
  • This problem does not occurs when using add_from_string, or add_from_file, however this seems to be speciously related to paths (declaration or usage)

I don’t think this is related to the language binding, but I could be wrong.

Thanks you!

it doesn’t look like exampleapp.c is actually compiled or linked.

Hi, thank you for you interest to help.
Those files (src/exampleapp.c, and include/exampleapp.h) are the output of glib-compile-resources --generate-header and glib-compile-resources --generate-source.
The binary is the result of not specifying those parameters
I did get a binary but I didn’t want to use it given that the documentation says it is not what people normally do.

PS I could try … make the project to use the binary instead. It is something to explore. I will let you know if it works

New update: I’ve also found an error with the Makefile because instead of editing the rule to update-sources-list I changed the rule for format the code so the files were not getting included in the sources to get compiled by cmake. But that happened only in this sample project, the update-sources-list rule was working as expected in the project I’m working and it didn’t work. HOWEVER, I think you’re right. Indicating a target could work. I’m sure cmake will not compile a .gresource along the C++ files however I can indicate the target as parameter. So this could work and you would be right

I’ve created a new branch (dev). That branch is using the generated file.
You may find this output of glib-compile-resources more familiar, however link that to the project is not as easy as pushing the files because now I have to build this target_sources I’ve incorporated (without reading the full description on cmake documentation I should add).
I need to build this target not just link to the executable.

I guess that’s the reason people prefer to use the header and source files.

Thank you for the suggestion though

Try a topic like this: gtk - How to use glib-compile-resources with CMake - Stack Overflow

You will need to build that with a C compiler, not a C++ one, then link both in the final application.

1 Like

I will try.
But I think I have to give some update of what I’ve tried already in case this doesn’t work or in case some one else provide a solution:

  • branch main was compiling the sources along the project’s source and headers (didn’t work)

  • branch nither-as-a-library was using this files (header and source produced by glib-compile-resources) to build a library and then link that library to the project’s executable (didn’t work)

  • branch dev is not properly configured (the cmake command was used incorrectly) so the main utility/purpose of that branch was to expose the file already processed by glib-configure-resources (not as a source or header file). The problem with using this tyle type is that cmake does not build the target so I need a different cmake command to integrate that executable.

As I said I will try this approach. I saw this type of usage and I have to say I dislike it. There is no point in doing all that extra work when I can run the command to produce the sources (or gresource). All I need to do is link it to the executable. I’m really surprised the branch neither-as-a-library didn’t work honestly

OK, done! It was fault of a task in the Makefile set incorrectly. I fixed that in another branch but not in main which was using the header and source files generated by glib-compile-resources correctly. I think it has to be dev because dev was not linking the resources to the project correctly, hence it didn’t work either.
I will take look at neighter-as-a-librarybranch again because that one was using the files to build a library and link it correctly.
Anyway what is important is that this should work and now it does.

Note: It does need the declaration of C language along the c++ to work correctly, i.e.

project(mre VERSION 0.1.0 LANGUAGES C CXX)

otherwise it wont work.

Thank you all for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.