What's the accepted method for deploying a linux application that relies on shared libraries?

前端 未结 3 1102
暖寄归人
暖寄归人 2020-12-08 03:12

I have an application that relies on Qt, GDCM, and VTK, with the main build environment being Qt. All of these libraries are cross-platform and compile on Windows, Mac, and

相关标签:
3条回答
  • 2020-12-08 03:16

    In general, you're best off depending on the 'normal' versions of the libraries for whatever distribution you're targetting (and saying you don't support dists that don't support recent enough versions of the lib), but if you REALLY need to depend on a bleeding edge version of some shared lib, you can link your app with -Wl,-rpath,'$ORIGIN' and then install a copy of the exact version you want in the same directory as your executable.

    Note that if you use make, you'll need $$ in the makefile to get a single $ into the argument that is actually sent to the linker. The single qutoes are needed so the shell doesn't munge things...

    0 讨论(0)
  • 2020-12-08 03:26

    Every "serious" commercial application I have ever seen uses LD_LIBRARY_PATH. They invariably include a shell script that looks something like this:

    #!/bin/sh
    
    here="${0%/*}"  # or you can use `dirname "$0"`
    
    LD_LIBRARY_PATH="$here"/lib:"$LD_LIBRARY_PATH"
    export LD_LIBRARY_PATH
    exec "$0".bin "$@"
    

    They name this script something like .wrapper and create a directory tree that looks like this:

    .wrapper
    lib/  (directory full of .so files)
    app1 -> .wrapper (symlink)
    app1.bin (executable)
    app2 -> .wrapper (symlink)
    app2.bin (executable)
    

    Now you can copy this whole tree to wherever you want, and you can run "/path/to/tree/app1" or "/path/to/tree/app2 --with --some --arguments" and it will work. So will putting /path/to/tree in your PATH.

    Incidentally, this is also how Firefox and Chrome do it, more or less.

    Whoever told you not to use LD_LIBRARY_PATH is full of it, IMHO.

    Which system libraries you want to put in lib depends on which Linux versions you want to officially support.

    Do not even think about static linking. The glibc developers do not like it, they do not care about supporting it, and they somehow manage to break it a little harder with every release.

    Good luck.

    0 讨论(0)
  • 2020-12-08 03:28

    Well, there are two options for deploying Linux application.

    The correct way:

    • make a package for your app and for the libraries, if they are so special, that they can't be installed from standard repositories

    • There are two major package formats. RPM and DEB.

    The easy way:

    • make a self-extract file that will install the "windows way" into /opt.

    • You can have libraries in the same directory as the executable, it's just not the preferred way.

    0 讨论(0)
提交回复
热议问题