probonopd / go-appimage

Go implementation of AppImage tools
MIT License
676 stars 69 forks source link

Guessed qt_prfxpath wrong (Qt 5 gets deployed instead of Qt 6) #268

Open VioletGiraffe opened 7 months ago

VioletGiraffe commented 7 months ago

The problem is well illustrated by this log. Qt 6 dependency is detected (correctly), but Qt 5 is deployed. Looks like it could be because Qt 5 was the first folder where it found libqxcb.so?..

2023/11/16 23:34:41 Detected Qt 6
2023/11/16 23:34:41 Offset of qt_prfxpath: 3522924
2023/11/16 23:34:41 Length of value of qt_prfxpath: 4
2023/11/16 23:34:41 qt_prfxpath: /usr
2023/11/16 23:34:41 Got qt_prfxpath but it does not contain 'plugins'
2023/11/16 23:35:28 libqxcb.so found: [/usr/lib/aarch64-linux-gnu/qt5/plugins/platforms/libqxcb.so /usr/lib/aarch64-linux-gnu/qt6/plugins/platforms/libqxcb.so]
2023/11/16 23:35:28 Guessed qt_prfxpath to be /usr/lib/aarch64-linux-gnu/qt5
2023/11/16 23:35:28 Looking in /usr/lib/aarch64-linux-gnu/qt5/plugins
probonopd commented 7 months ago

Guessed qt_prfxpath to be /usr/lib/aarch64-linux-gnu/qt5

This is the issue. It is wrong (assumig you want Qt6). We need to fx it. Volunteers?

This whole guessing is not reliable. What would be a more robust way to know which Qt to use, and from where?

VioletGiraffe commented 7 months ago

That is a good question, I navigated the Qt folders a bit and it all looks like a bunch of mess. But it does work. How do the Qt .so libraries know where to look for plugins? They're not in the same parent folders as is the case on Windows.

>  qmake -v
Using Qt version 6.4.2 in /usr/lib/aarch64-linux-gnu
> ldd bin/myapp
libQt6Gui.so.6 => /lib/aarch64-linux-gnu/libQt6Gui.so.6 (0x0000007fa97a0000)
libQt6Core.so.6 => /lib/aarch64-linux-gnu/libQt6Core.so.6 (0x0000007fa92b0000)

So the question is, as far as I understand, how to locate the plugins. They're not in /usr/lib/aarch64-linux-gnu/ but instead in /usr/lib/aarch64-linux-gnu/qt6/.

probonopd commented 7 months ago

How do the Qt .so libraries know where to look for plugins?

The string qt_prfxpath is hardcoded in one of the Qt .so libraries. It's pretty much under-documented, though.

And sometimes, it's even outright wrong.

VioletGiraffe commented 7 months ago

Okay, judging from the appimagetools log the string says just /usr, that's wrong as there are no plugins there. But somehow Qt works fine.

probonopd commented 7 months ago

Black magic!

probonopd commented 7 months ago

So the question is, as far as I understand, how to locate the plugins. They're not in /usr/lib/aarch64-linux-gnu/ but instead in /usr/lib/aarch64-linux-gnu/qt6/.

... but currently go-appimage (wrongly)

Guessed qt_prfxpath to be /usr/lib/aarch64-linux-gnu/qt5

probonopd commented 7 months ago

All I can tell you at the moment is that the bug is somewhere in

https://github.com/probonopd/go-appimage/blob/53294ec0fa99b89babd598e087e859259ed32625/src/appimagetool/appdirtool.go#L1471-L1490

probonopd commented 7 months ago

In the meantime, try export QTDIR=/usr/lib/aarch64-linux-gnu/qt6/ before running linuxdeployqt. Do this on a new AppDir (one which linuxdeployqt was never run on before).

VioletGiraffe commented 7 months ago

As for the code: you take the 1st result which happened to be qt5 (or it will always be qt5 based on alphabetical sorting), instead you should check whether it's Qt5 or 6 - you already know that Qt 6 is required. I'm not a fan of writing even more complex fragile heuristics, but in this case seems inevitable as the current solution simply doesn't support Qt 6 .

Upd: or you can remove the guessing altogether and require QTDIR to be defined if qt_prfxpath does not contain "plugins".

VioletGiraffe commented 7 months ago

In the meantime, try export QTDIR=/usr/lib/aarch64-linux-gnu/qt6/ before running linuxdeployqt.

That worked! The correct paths are in the log now, and the AppImage size is reduced. However, it still doesn't run:

Failed to load the image at
Press any key to exit.

Any ideas? What can I do to troubleshoot this?

probonopd commented 7 months ago

Is that message coming from your program?

VioletGiraffe commented 7 months ago

You're right, sincere apologies. I was so puzzled by the message that I was certain it's from the AppImage runtime. And many thanks for your help!