简体   繁体   English

pybind11 方法如何最终调用共享库中的函数?

[英]How does pybind11 methods end up calling functions from the shared library?

I can make as much out as its build system generates a shared object, and also a Python module as a proxy to that shared object.我可以做出尽可能多的构建系统生成共享 object 和 Python 模块作为共享 object 的代理。 But how does the Python runtime end up doing a dlopen of the generated shared object and bind Python method calls on to corresponding functions in the shared library?但是 Python 运行时如何最终对生成的共享 object 进行dlopen并绑定 Python 方法调用到共享库中的相应函数?

I also found a reference in Python's import system about shared libraries, but nothing beyond that.我还在Python 的导入系统中找到了关于共享库的参考,但除此之外没有其他内容。 Does CPython treat .so files in the module path as Python modules? CPython 是否将模块路径中的.so文件视为 Python 模块?

When doing import module Python will look for files with various extensions that could be python modules.import module Python 将查找具有各种扩展名的文件,这些文件可能是 python 模块。 That can be module.py , but also module.so (on Linux) or module.pyd (on Windows).这可以是module.py ,也可以是module.so (在 Linux 上)或module.pyd (在 Windows 上)。

When loading a shared object, Python will load it like any dynamic library and then it will call the module's init method: It must be named PyInit_{module_name_here} and exported in the shared library.加载共享 object 时,Python 将像任何动态库一样加载它,然后调用模块的 init 方法:它必须命名为PyInit_{module_name_here}并导出到共享库中。

You can read more about it here .你可以在这里阅读更多关于它的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM