How to use Cython to create a stand dll

前端 未结 2 2033
春和景丽
春和景丽 2020-12-29 11:45

I have a Python script, I renamed the script to .pyx file. I want compile this code to a stand dll file.

I saw in this document that Cython will create a dll file, b

2条回答
  •  渐次进展
    2020-12-29 12:10

    Is a *.pyd file the same as a DLL?

    Yes, .pyd files are dll’s, but there are a few differences. If you have a DLL named foo.pyd, then it must have a function PyInit_foo(). You can then write Python “import foo”, and Python will search for foo.pyd (as well as foo.py, foo.pyc) and if it finds it, will attempt to call PyInit_foo() to initialize it. You do not link your .exe with foo.lib, as that would cause Windows to require the DLL to be present.

    Note that the search path for foo.pyd is PYTHONPATH, not the same as the path that Windows uses to search for foo.dll. Also, foo.pyd need not be present to run your program, whereas if you linked your program with a dll, the dll is required. Of course, foo.pyd is required if you want to say import foo. In a DLL, linkage is declared in the source code with __declspec(dllexport). In a .pyd, linkage is defined in a list of available functions.

    Modifying Python’s Search Path, Absolute and Relative Imports

提交回复
热议问题