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

前端 未结 3 1112
暖寄归人
暖寄归人 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: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.

提交回复
热议问题