Python C extension: Use extension PYD or DLL?

后端 未结 4 888
[愿得一人]
[愿得一人] 2020-12-13 09:21

I have a Python extension written in C and I wonder if I should use the file extension DLL or PYD under Windows. (And what would I use in Linux?)

Are there any diffe

4条回答
  •  渐次进展
    2020-12-13 10:24

    In Windows you can use *.pyd to be imported directly from Python import foo but for *.dll you should use this:

    from ctypes import cdll
    #load dll file , the file in the same .py file location or enter the full path
    mylib=cdll.LoadLibrary("foo.dll") 
    #call a function from this dll (c-ext) 
    ReturnedValue=mylib.FunctionName()
    

    If you want to explore what functions are exported in this Dll use this tool

    UPDATE: Here's an example using distutils and SWIG to build the extension. Check this article out, it shows many simple examples under Windows and Linux.

提交回复
热议问题