Recent

Author Topic: Problem distributing Lazarus compiled application under Linux  (Read 2755 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Problem distributing Lazarus compiled application under Linux
« on: February 05, 2020, 10:40:51 pm »
Dear ALL,

So, I have created a cross-platform application with compiled 32-bit binaries for both MS-Windows and GNU/Linux. The Windows version has been compiled with Lazarus 2.0.6 under Windows 10 Home (64-bits) and the Linux version has been compiled with Lazarus 1.8.2+dfsg-3 under Mint Linux 19.1 Xfce (32-bit).

Both versions work well in their respective operating systems. I then created distribution packages for each version, using InnoSetup (http://www.jrsoftware.org/isinfo.php) for the Windows version and Debreate (https://antumdeluge.github.io/debreate-web) for the Linux version.

Everything looked fine until a Linux user (Users! Send us more! The last one were delicious!) found a dependency problem with the Debian package. He is using Ubuntu Mate 18.04 (64-bits). The Debian package does not start because "fde: error while loading shared libraries: libgdk-x11-2.0.so.0: cannot open shared object file: No such file or directory" (where "fde" is the name of the application binary included in the Debian package). It short, it seems that my application depends on a shared library ("libgdk-x11-2.0.so.0") which is present in my Linux distribution but not on the one used by him.

Dependency problems can be addressed by Debreate and so this ie not really the issue. What I would like to ask is: (i) why is this specific shared library required? (ii) are there any other such libraries which are necessary for running Lazarus applications under any Linux distribution? (iii) is there any way to know in advance what are all the dependencies required by Lazarus binary applications under Linux?

I found some similar topics here in the forum:

https://forum.lazarus.freepascal.org/index.php?topic=5032.0

https://forum.lazarus.freepascal.org/index.php?topic=37430.0

https://forum.lazarus.freepascal.org/index.php?topic=42438.0


but none of them addressed the issue I am presenting here for discussion.

As always, thanks in advance for any assistance you can provide.

With best regards,
« Last Edit: May 27, 2020, 01:56:11 am by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: Problem distributing Lazarus compiled application under Linux
« Reply #1 on: February 06, 2020, 02:18:30 am »
(iii) is there any way to know in advance what are all the dependencies required by Lazarus binary applications under Linux?
Question #3 was answered in the posts you found

Use ldd and/or readelf to list dependencies for an executable.
   readelf -d /path/to/executable | grep NEEDED
   or
   ldd /path/to/executable

Google finds the same:  https://www.google.com/search?q=linux+show+executable+dependencies

If you want to find the packages which contain the missing files, on Ubuntu and Debian derivatives, use dpkg -S filename to search:
Code: Bash  [Select][+][-]
  1. dpkg -S libgdk-x11-2.0.so.0
  2. libgtk2.0-0:amd64: /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.30
  3. libgtk2.0-0:i386: /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0
  4. libgtk2.0-0:amd64: /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
  5. libgtk2.0-0:i386: /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0.2400.30
  6.  

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Problem distributing Lazarus compiled application under Linux
« Reply #2 on: February 06, 2020, 07:36:12 am »
Wayne has some good suggestions but sometimes its not quite that simple. Should be but ....

Here is the depends line for my app when making debs -
Code: Pascal  [Select][+][-]
  1. Depends: libgtk2.0-0 (>= 2.6), libc6 (>= 2.14), libcanberra-gtk-module, appmenu-gtk2-module

From memory, libgtk2.0 will bring in libgdk2.0.  And yes, your default Lazarus app will require GTK2.

More interesting is libcanberra-gtk-module, not used in my app, not listed by ldd as a dependency but if its not there, lots of complaints. Sigh.

And appmenu-gtk2-module is even more interesting ! We have found that Ubuntu 19.10 goes into some ill defined time out if its not present.  Does not seem to be a problem on any other systems and I am eagerly waiting for U20.04 to see if it has the same problem. Its about connecting legacy GTK2 apps to the GTK3 DBus system, used for talking to menus, status bars, system tray.

But the issue is that older versions of Linux, such as U16.04, still a supported system and MXLinux, do not have appmenu-gtk2-module, so cannot use the same deb !  I suspect Canonical should have included appmenu-gtk2-module as a dependency of gtk2.0 on U19.10. The underlying problem is that GTK2 is not being installed by default any more on more and more linux systems so expect a lot of these sort of problems.

I am currently debating how to handle this in my next release, I don't want to have two different debs but feel bad about about cutting those users of old systems loose. I think I may drop mention of  appmenu-gtk2-module but tell U19.10 users they also need to manually install it. Of course, with nothing officially using it, they will get prompted to remove it at some stage ....

And if we see the same problem in U20.04, a long term release ???

A better approach may be to tell users of newer systems to use a Qt5 version, the necessary Qt5 libraries are a lot smaller download than GTK2 and, perhaps more likely to be needed by other apps anyway. Perhaps.  Your app maurobio will build fine with Qt5 if you use a bit more current version of Lazarus than 1.8.4

Oh, but don't use the Qt5 version on Fedora, it uses Wayland by default and that does not play nicely with Qt5.

There, you asked for some discussion !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problem distributing Lazarus compiled application under Linux
« Reply #3 on: February 06, 2020, 11:59:29 am »
Dears @WaynneSherman and @dbannon,

Thanks a lot for the very insightful tips, comments, and suggestions.

@dbannon especially made the issue clear, because I was not sure if the dependency was 'libgdk2.0' only or if it was in fact the 'libgtk2.0' (as one should have suspected). 

I see no better way other than to adopt a trial-and-error approach, adding the required dependencies as they appear, as well as informing users that the application may not work on all distributions of Linux.

Again, thank you very much!

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Problem distributing Lazarus compiled application under Linux
« Reply #4 on: February 06, 2020, 12:46:23 pm »
*snipp* and the Linux version has been compiled with Lazarus 1.8.2+dfsg-3 under Mint Linux 19.1 Xfce (32-bit).
*snipp*
Not really anything to the original discussion:
BIG NO NO!
the "dfsg-3" is a dead give-away, that you've installed FPC/Lazarus from the Distro-repo's!
Just search the forum for installing Lazarus on Linux with FPC/Laz downloaded from here vs. Install from repos.
The Distro-Maintainers (Canonical for Ubuntu which Mint is based on) just created a big mess with their repo-version.
e.g. some years ago (on 18.04 or think) i installed from repo's, and couldn't compile using QT5 (wrong paths, packages missing etc.)
« Last Edit: February 06, 2020, 12:48:13 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problem distributing Lazarus compiled application under Linux
« Reply #5 on: February 06, 2020, 01:07:11 pm »
Dear @Zvoni,

Thanks for your comments.

My applications works perfectly well on my Mint Linux system, compiled with Lazarus 1.8.2+dfsg-3 installed from the official repositories. That's not my current problem - my problem is in creating a distribution package with all the correct dependencies to allow the application to run on other Linux systems. As far as I can see, this mainly concerns the need for GTK2 to be installed in the users' system.

But as soon as possible, I will upgrade my installation of FPC/Lazarus to a more recent one (under Windows, I use version 2.0.6).

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

bee

  • Sr. Member
  • ****
  • Posts: 393
Re: Problem distributing Lazarus compiled application under Linux
« Reply #6 on: February 06, 2020, 01:57:54 pm »
Welcome to the Linux world. Linux honors liberty and freedom so much that Linux distros has no official standards upon the distributions. If on Windows there’s “dll hell”, on Linux you face “distro hell”. It’s pretty much the same. :D
-Bee-

A long time pascal lover.

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: Problem distributing Lazarus compiled application under Linux
« Reply #7 on: February 06, 2020, 03:47:07 pm »
Use ldd and/or readelf to list dependencies for an executable.

For completeness, ldd and readelf may give different results. ldd is recursive and should also list dependencies of dependencies.

See here:
https://stackoverflow.com/questions/15064685/does-ldd-also-show-dependencies-of-dependencies/15064784

Quote
ldd shows all libraries that it would need to load when starting the application or loading a shared library.
readelf -d shows only direct dependencies of the binary.

and here:
https://stackoverflow.com/questions/1488527/hierarchical-ldd1/1490497
Quote
..what ldd does is to get the dynamic linker to do load the executable or library as it usually would, but print out
 some info along the way. This is a recursive "binary needs library needs other library&hellip" search,
 because that's what the dynamic linker does.

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: Problem distributing Lazarus compiled application under Linux
« Reply #8 on: February 06, 2020, 04:11:07 pm »
Also, ldd will not show dependencies which are dynamically loaded at run-time.

To list all dependencies, whether dynamically linked or dynamically loaded:

https://unix.stackexchange.com/a/358500
and
https://stackoverflow.com/a/5103749

Quote
ldd and lsof show the libraries loaded either directly or at a given moment. They do not account for libraries loaded via dlopen (or discarded by dlclose). You can get a better picture of this using strace, e.g.,

Quote
cat /proc/NNNN/maps | awk '{print $6}' | grep '\.so' | sort | uniq

Or, with strace:
strace CMD.... 2>&1 | grep -E '^open(at)?(.*\.so'

Both of these assume that shared libraries have ".so" somewhere in their paths, but you can modify that. The first one gives fairly pretty output as just a list of libraries, one per line. The second one will keep on listing libraries as they are opened, so that's nice.

And of course lsof...
lsof -p NNNN | awk '{print $9}' | grep '\.so'
« Last Edit: February 06, 2020, 04:16:57 pm by WayneSherman »

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Problem distributing Lazarus compiled application under Linux
« Reply #9 on: February 07, 2020, 12:00:21 am »
While I have not followed the links provided, I bet they mention strace.  It is, beyond doubt, the best tool to see whats happening.  Its pretty wordy but does accept a number of options to only reports particular actions.

The idea is you get strace to run your app, you do what ever you do with that app and strace is reporting on most system interaction as you go.  Most useful I find is to dump all of that output into a file and then use grep to trawl through it.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018