From f76153f96bc76862f3ffb1416b589c52c50b4d36 Mon Sep 17 00:00:00 2001 From: probonopd Date: Tue, 3 Sep 2024 19:52:54 +0200 Subject: [PATCH 1/2] Also use $QT_ROOT_DIR Also use the environment variable `$QT_ROOT_DIR` https://github.com/probonopd/go-appimage/issues/300#issuecomment-2323463775 --- src/appimagetool/appdirtool.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/appimagetool/appdirtool.go b/src/appimagetool/appdirtool.go index 842704d..ff4ed54 100644 --- a/src/appimagetool/appdirtool.go +++ b/src/appimagetool/appdirtool.go @@ -1492,11 +1492,14 @@ func handleQt(appdir helpers.AppDir, qtVersion int) { func getQtPrfxpath(f *os.File, err error, qtVersion int) string { - // If the user has set $QTDIR, use that instead of the one from qt_prfxpath in the library + // If the user has set $QTDIR or $QT_ROOT_DIR, use that instead of the one from qt_prfxpath in the library qtPrefixEnv := os.Getenv("QTDIR") + if qtPrefixEnv == "" { + qtPrefixEnv = os.Getenv("QT_ROOT_DIR") + } if qtPrefixEnv != "" { - log.Println("Using $QTDIR:", qtPrefixEnv) - return qtPrefixEnv + log.Println("Using QTDIR or QT_ROOT_DIR:", qtPrefixEnv) + return qtPrefixEnv } f.Seek(0, 0) From 2013fbd66a7cdd689be9cdf39e65742fc646c32b Mon Sep 17 00:00:00 2001 From: probonopd Date: Wed, 4 Sep 2024 21:00:06 +0200 Subject: [PATCH 2/2] Check for the return value of prfxpathPos https://github.com/probonopd/go-appimage/issues/300#issuecomment-2328288496 Thanks @kevle --- src/appimagetool/appdirtool.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/appimagetool/appdirtool.go b/src/appimagetool/appdirtool.go index ff4ed54..01c1ef2 100644 --- a/src/appimagetool/appdirtool.go +++ b/src/appimagetool/appdirtool.go @@ -511,7 +511,12 @@ func patchQtPrfxpath(appdir helpers.AppDir, lib string, libraryLocationsInAppDir f.Seek(0, 0) // Search from the beginning of the file search := []byte("qt_prfxpath=") - offset := ScanFile(f, search) + int64(len(search)) + prfxpathPos := ScanFile(f, search) + if prfxpathPos < 0 { + helpers.PrintError("Could not find offset for " + string(search), errors.New("no " + string(search) + " token in binary")) + os.Exit(1) + } + offset := prfxpathPos + int64(len(search)) log.Println("Offset of qt_prfxpath:", offset) /* What does qt_prfxpath=. actually mean on a Linux system? Where is "."?