How does ctypes.cdll.LoadLibrary(None) work?

后端 未结 1 821
难免孤独
难免孤独 2020-12-11 05:40

How does ctypes.cdll.LoadLibrary() call work with None passed in as an argument? When I try the code below, it seems that the math lib

相关标签:
1条回答
  • 2020-12-11 05:46

    Note: You encountered this on Nix (on Win it isn't reproducible).

    Take a look at [SO]: How to check whether a file exists without exceptions? (@CristiFati's answer).
    There, in the last part (the Notes section) of item #4, I explained this exact scenario, quoting the following passage from [man7]: DLOPEN(3):

    If filename is NULL, then the returned handle is for the main program. When given to dlsym(), this handle causes a search for a symbol in the main program, followed by all shared objects loaded at program startup, and then all shared objects loaded by dlopen() with the flag RTLD_GLOBAL.

    which is used when loading libraries, according to [Python 3]: Loading shared libraries:

    All these classes can be instantiated by calling them with at least one argument, the pathname of the shared library. If you have an existing handle to an already loaded shared library, it can be passed as the handle named parameter, otherwise the underlying platforms dlopen or LoadLibrary function is used to load the library into the process, and to get a handle to it.

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