Score:1

Cannot run an app that uses GTK without root

sj flag

I wrote a very simple executable in C++, that uses opencv with gtk3 to load an image in jpeg format and show it, When I run it without sudo, I got error:

Gtk-WARNING **: 21:58:36.172: Could not load a pixbuf from icon theme.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Fatal error reading PNG image file: Invalid IHDR data (gdk-pixbuf-error-quark, 0)
Bail out! Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Fatal error reading PNG image file: Invalid IHDR data (gdk-pixbuf-error-quark, 0)
[1]    6329 IOT instruction  ./main 

But if I run it with sudo, everything works. I searched around and tried all the suggested commands that I found online including:

sudo apt reinstall libgdk-pixbuf2.0-0
sudo /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders --update-cache
sudo update-mime-database /usr/share/mime
sudo chmod -R uga-x /usr/share/mime; sudo chmod -R uga+X /usr/share/mime

None of above works, I also restarts the system after running all the steps, still does not work, need help.

I am on Ubuntu 18.04, in WSL2, I also tested the binary in a freshly installed ubuntu 20.04 in WSL2 and the same thing happens. The source code and binary can be downloaded at https://github.com/shelper/vscode_cpp_cmake_example/releases/tag/test.

sj flag
updated, i am on ubuntu 18.04 on wsl2, i am not sure if i understand you, but all the commands i listed above, need to be run with sudo and i also updated access with chmod...
NotTheDr01ds avatar
vn flag
Does it happen with any "out-of-the-box" Gtk app, or just your code? If just yours, can you add a possible [MRE](https://stackoverflow.com/help/minimal-reproducible-example), and I'll see if I can reproduce and help out. Also, does `wsl --version` show any results? If so, probably worth adding them to the question as well so I can try a similar environment. Thanks!
NotTheDr01ds avatar
vn flag
Also, is `XDG_DATA_DIRS` set and valid per [this answer](https://askubuntu.com/a/1388056/1165986)?
sj flag
Its just my code, and i also tried to set XDG_DATA_DIRS, which is unset originally. I updated my question with src and binary for download and test
NotTheDr01ds avatar
vn flag
Ah, I'm sorry I pushed to repost over here then. It probably would be better on Stack Overflow as you thought, but it would have been closed anyway without an MRE. However, we could have reopened it there with the MRE. I'll leave it to you where you want to leave it. My personal opinion will be that, if you have source code in the question itself, you'll likely stand a better chance of having it answered on Stack Overflow. I'll continue to look at it regardless, though, but it may be out of my depth.
sj flag
@NotTheDr01ds see my own answer below. it is kinda solved but leaves new question..
Score:1
sj flag

I found this article at https://devforum.play.date/t/segmentation-fault-running-playdatesimulator-on-linux/3360/4, I then tried the sed -i s/png_/PNG_/g ./main, I got error saying undefined symbol: G_free. I then rebuild the binary and run sed -i s/png_/PNg_/g ./main, everything works now. I believe this is due to the gtk-3 dev package I used to build OpenCV has ABI compatibility with the one in my system. However, what I don't understand is that why sudo is able to run the binary without problem.

NotTheDr01ds avatar
vn flag
Good find! I'm wondering - Is the image that you are trying to load on a Windows mount such as `/mnt/c`? Or is it on the WSL2 ext4 filesystem?
sj flag
it is in WSL2, the same folder as the main that is in my home directory in WSL2
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.