LD_LIBRARY_PATH

后端 未结 3 1112
死守一世寂寞
死守一世寂寞 2021-01-14 08:04

Can I set LD_LIBRARY_PATH for an individual application? I am looking into system call failure, so is there any way I can set set the correct path using the LD_LIBRARY_PATH

相关标签:
3条回答
  • 2021-01-14 08:20

    As simple as:

    LD_LIBRARY_PATH=new_path:$LD_LIBRARY_PATH foo
    

    which works in bash. I think it works in all bourne shell derivatives, but I can't guarantee it.

    Of course, with this approach, you have to type the path every time. To do it repeatedly, prefer Glen's approach.

    0 讨论(0)
  • 2021-01-14 08:34

    Simplest way would be to create a shell script.

    Have the shell script export your new LD_LIBRARY_PATH variable then launch your application

    e.g. (where foo is your app)

    #!/bin/sh
    LD_LIBRARY_PATH=some_path:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH
    foo
    
    0 讨论(0)
  • 2021-01-14 08:38

    One item to be aware of: you cannot set LD_LIBRARY_PATH within a program and make it have any effect on the current program. This is because the dynamic loader (ld.so.1 or some similar name) is already loaded and has read and processed the environment variable before any of your code is run. You can set it in the current process's environment, and that value will then affect any child processes, and you could use one of the exec() family of functions to run a program with the environment set. In an extreme case, you could re-execute the current program - but that is extreme!

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