Ticket #4343 - OPENSCAD not working with AppImage distros

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
wsy
Posts: 3
Joined: Fri May 17, 2019 4:53 pm

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by wsy »

4343 is still with us as of build 25943 (October 10, 2021) on freshly-updated Debian Testing.

Emptying LD_LIBRARY_PATH does not help.

libQt5Core.so appears to be in the right place:

wsy@max:/lib/x86_64-linux-gnu$ pwd
/lib/x86_64-linux-gnu
wsy@max:/lib/x86_64-linux-gnu$ ls -la libQt5Core*
-rw-r--r-- 1 root root 1204 Sep 23 09:02 libQt5Core.prl
lrwxrwxrwx 1 root root 20 Sep 23 09:02 libQt5Core.so -> libQt5Core.so.5.15.2
lrwxrwxrwx 1 root root 20 Sep 23 09:02 libQt5Core.so.5 -> libQt5Core.so.5.15.2
lrwxrwxrwx 1 root root 20 Sep 23 09:02 libQt5Core.so.5.15 -> libQt5Core.so.5.15.2
-rw-r--r-- 1 root root 5552552 Sep 23 09:02 libQt5Core.so.5.15.2
wsy@max:/lib/x86_64-linux-gnu$
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by chennes »

Thanks for the update and re-test. I'll start looking into this.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by chennes »

wsy wrote: Sun Oct 10, 2021 10:40 pm 4343 is still with us as of build 25943 (October 10, 2021) on freshly-updated Debian Testing.
A couple of questions for you:
  1. How is your OpenSCAD installed (e.g. normal, Snap, AppImage, etc.)? Which version is it?
  2. Did you test using the "pipes" transfer mechanism (found in the FreeCAD OpenSCAD WB preferences)?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
lrak
Posts: 34
Joined: Fri Feb 22, 2019 12:33 am

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by lrak »

Still have the bug with FreeCAD_weekly-builds-26720-Linux-Conda_glibc2.12-x86_64.AppImage

/usr/bin/openscad: /tmp/.mount_FreeCAGwvdPR/usr/lib/libQt5Core.so.5: version `Qt_5.15' not found (required by /usr/bin/openscad)

I can see the lib is installed - Debian bullseye:
libqt5core5a is already the newest version (5.15.2+dfsg-9).

Probably is a matter of linking to it - mentioned in an earlier post as a workaround - but missing the details.

I think one needs to set LD_LIBRARY_PATH in the shell that calls theAppImage - but nothing I tried worked.

,.,.
I see libQt5Core.so.5 is in /tmp/.mount_FreeCAGwvdPR/usr/lib/

/tmp/.mount_FreeCAK71CoQ/usr/lib$ ls libQt5Core*
libQt5Core.prl libQt5Core.so libQt5Core.so.5 libQt5Core.so.5.12 libQt5Core.so.5.12.9

Looks like the right version is missing? A build-bot that makes deb packages would be a good idea.
I would rather have questions that cannot be answered,
than answers that cannot be questioned’
Richard Feynman.
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by thomas-neemann »

lrak wrote: Sun Jan 02, 2022 7:15 pm Still have the bug with FreeCAD_weekly-builds-26720-Linux-Conda_glibc2.12-x86_64.AppImage

/usr/bin/openscad: /tmp/.mount_FreeCAGwvdPR/usr/lib/libQt5Core.so.5: version `Qt_5.15' not found (required by /usr/bin/openscad)
..
here it works

OS: Ubuntu 20.04.1 LTS (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.26720 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 7bca26e)
Hash: 7bca26e7c14d4d43374ff7e0c8582735b249cbfd
Python version: 3.9.9
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: German/Germany (de_DE)
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by chennes »

Which transfer mechanism are you using? Is this with the new pipe mechanism?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
lrak
Posts: 34
Joined: Fri Feb 22, 2019 12:33 am

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by lrak »

I did a bunch of digging - this appears to be a limitation of working with the AppImage distros.

Went back to running under Debian bullseye - 0.19 it works -

To recreate - just open OpenScad workbench - add openscad element and enter some code.. see errors..
I would rather have questions that cannot be answered,
than answers that cannot be questioned’
Richard Feynman.
lamikr
Posts: 14
Joined: Fri Jul 08, 2022 11:44 pm

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by lamikr »

As information is little scattered this one having multiple bug tickets, I will gather all I found first to here:

1) Original bug ticket with suggested good fix:
https://tracker.freecadweb.org/view.php?id=4343

2) Same ticket opened as a 2 new tickets for freecad-bundle on github
https://github.com/FreeCAD/FreeCAD-Bundle/issues/56
https://github.com/FreeCAD/FreeCAD-Bundle/issues/107
lamikr
Posts: 14
Joined: Fri Jul 08, 2022 11:44 pm

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by lamikr »

freecad_appimage_020_openscad_qt5_15_launch_fix.txt
Patch to fix the openscad invokation errors
(2.33 KiB) Downloaded 28 times
I get the same error with FreeCAD-0.20.0-Linux-x86_64.AppImage that was originally described in the first post. Also the fix suggested there works for me.
<class 'OpenSCADUtils.OpenSCADError'>: " /usr/bin/openscad: /tmp/.mount_FreeCAhhHfre/usr/lib/libQt5Core.so.5: version `Qt_5.15' not found (required by /usr/bin/openscad)\n/usr/bin/openscad: /tmp/.mount_FreeCAhhHfre/usr/lib/libQt5Core.so.5: version `Qt_5.15' not found (required by /lib64/libqscintilla2_qt5.so.15)\n"
Fix is to patch the /usr/Mod/OpenSCAD/OpenSCADUtils.py function so that the libraries are first tried to load from the linux distro before fallbacking to appimage versions when launching the openscad executable.
Reason why this fix is needed is that when the freecad launches the external openscad from appimage,
the external openscad depends from the distro specific library versions instead of the one offered by the appimage.

In my case from the libqscintilla2_qt5.so.15 is not available in appimage and that depends from the qt5.15 version and try to load the libQt5Core.so.5.

But in freecad appimage the symlink
/tmp/.mount_FreeCAhhHfre/usr/lib/libQt5Core.so.5
points to libQt5Core.so.5.12.9 that is available in appimage instead of using the
/usr/lib64/libQt5Core.so.5
from linux distro that points to /usr/lib64/libQt5Core.so.5.15.2 and therefore the wrong version is found.

So it worked also for me to add the distro's librarypath before launching the openscad.
At least in my case I needed to do that to also in other function call where the openscad were called to check the version number.
So here is the full patch I needed:

Code: Select all

diff -Naur freecad_appimage_orig/usr/Mod/OpenSCAD/OpenSCADUtils.py freecad_appimage_fixed/usr/Mod/OpenSCAD/OpenSCADUtils.py
--- freecad_appimage_orig/usr/Mod/OpenSCAD/OpenSCADUtils.py	2022-07-10 20:49:58.231874740 -0700
+++ freecad_appimage_fixed/usr/Mod/OpenSCAD/OpenSCADUtils.py	2022-07-10 22:09:17.289272855 -0700
@@ -142,12 +142,31 @@
             "User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
             GetString('openscadexecutable')
     if osfilename and os.path.isfile(osfilename):
-        with subprocess.Popen([osfilename, '-v'],\
-            stdout = subprocess.PIPE,stderr=subprocess.PIPE, universal_newlines=True) as p:
+        env = os.environ.copy()
+        try:
+            env.pop('LD_LIBRARY_PATH')
+        except KeyError:
+            None  
+        def check_output2(*args, **kwargs):
+            env = os.environ.copy()
+            try:
+                env.pop('LD_LIBRARY_PATH')
+            except KeyError:
+                None
+            kwargs.update({'stdout':subprocess.PIPE,'stderr':subprocess.PIPE,'env':env})
+            p = subprocess.Popen(*args, **kwargs)
             p.wait()
-            stdout = p.stdout.read().strip()
-            stderr = p.stderr.read().strip()
-            return (stdout or stderr)
+            stdoutd = p.stdout.read().decode("utf8")
+            stderrd = p.stderr.read().decode("utf8")
+            if p.returncode != 0:
+                raise OpenSCADError('%s %s\n' % (stdoutd.strip(),stderrd.strip()))
+                #raise Exception,'stdout %s\n stderr%s' %(stdoutd,stderrd)
+            if stderrd.strip():
+                FreeCAD.Console.PrintWarning(stderrd+u'\n')
+            if stdoutd.strip():
+                FreeCAD.Console.PrintMessage(stdoutd+u'\n')
+            return (stdoutd or stderrd)
+        return check_output2([osfilename, '-v'])
 
 
 def newtempfilename():
@@ -173,7 +192,12 @@
     import time
 
     def check_output2(*args, **kwargs):
-        kwargs.update({'stdout':subprocess.PIPE,'stderr':subprocess.PIPE})
+        env = os.environ.copy()
+        try:
+            env.pop('LD_LIBRARY_PATH')
+        except KeyError:
+            None
+        kwargs.update({'stdout':subprocess.PIPE,'stderr':subprocess.PIPE,'env':env})
         p = subprocess.Popen(*args, **kwargs)
         stdoutd, stderrd = p.communicate()
         stdoutd = stdoutd.decode("utf8")


I applied the fix in a following way to existing freecad 0.20.0 appimage to test it.
  1. 1) Extract appimage
    ./FreeCAD-0.20.0-Linux-x86_64.AppImage --appimage-extract
  2. Move directory containing extracted appimage files
    cd squashfs-root
  3. Patch appimage with openscan launch fix for qt5 version problem
    patch -p1 < ../freecad_appimage_020_openscad_qt5_15_launch_fix.patch
  4. Move back to appimage directory
    cd ..
  5. Download appimagetool to create new appimage from fixed appimage files
    https://github.com/AppImage/AppImageKit/releases
  6. Generate new appimage with fix. This will generate a image with name "FreeCAD_Weekly-x86_64.AppImage"
    ./appimagetool-x86_64.AppImage ./squashfs-root
  7. Launch new appimage to test the openscad bug
    ./FreeCAD_Weekly-x86_64.AppImage
Last edited by lamikr on Wed Jul 13, 2022 5:37 pm, edited 1 time in total.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Ticket #4343 - OPENSCAD not working with AppImage distros

Post by chrisb »

lamikr wrote: Mon Jul 11, 2022 5:21 am
Please edit your post and put the code and output in code tags using the button </>. That makes the post easier to read and shows immediately if there are indentations or not.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply