Why the installed program has error when loading shared library in linux (cmake)

后端 未结 3 1702
说谎
说谎 2020-12-12 04:39

I have a question related to how to install a built executable program with cmake when it relies on some external libraries. Suppose my executable is abc, and i

3条回答
  •  孤街浪徒
    2020-12-12 04:53

    The libraries are searched in the predefined locations which includes standard library paths configured with ld.so.conf and LD_LIBRARY_PATH. You can also try to compile your app with -rpath, but it is not recommended by some developers. I suggest you to create a wrapper script which will set LD_LIBRARY_PATH and run the real application like that:

    "theapp" script:

    #!/bin/sh
    dir="`dirname \"$0\"`"
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}"$dir"
    exec "$dir/theapp.real" # your real application
    

    The application, script and libraries should be in the same location (under bin/).

提交回复
热议问题