Changing LD_LIBRARY_PATH at runtime for ctypes

后端 未结 5 1968
南笙
南笙 2020-11-27 15:14

How do you update this environment variable at runtime so that ctypes can load a library wherever? I\'ve tried the following and neither seem to work.

from c         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 15:42

    By the time a program such as Python is running, the dynamic loader (ld.so.1 or something similar) has already read LD_LIBRARY_PATH and won't notice any changes thereafter. So, unless the Python software itself evaluates LD_LIBRARY_PATH and uses it to build the possible path name of the library for dlopen() or an equivalent function to use, setting the variable in the script will have no effect.

    Given that you say it doesn't work, it seems plausible to suppose that Python does not build and try all the possible library names; it probably relies on LD_LIBRARY_PATH alone.

提交回复
热议问题