When I searched from Python to want to use a function written in C, I came to the conclusion that ctypes seems to be convenient this time, but when I got stuck in the first step (dll creation ~ read with python) Note.
http://flow-developers.hatenablog.com/entry/2017/12/19/075319
Windows10 (64bit)
Anaconda 64bit (Python 3.6.4)
Cygwin
-gcc -shared hoge.c -o hoge.dll
On the python side, the dll file created in
lib=ctype.CDLL("hoge.dll")
However, the error that python does not find the dll. I tried Cygwin with no use, but it certainly didn't work.
MinGW64
Although the dll can be found
[WinError 193] %1 is not a valid Win32 application DLL
Error. Python is 64bit, MinGW is also 64bit, why. .. Then it was discovered that mingw's gcc is 32bit. .. ..
Visual Studio 2017
I had no choice but to use VS. (X86_x64 Cross Tools Command Prompt for Visual Studio 2017.)
cl /LD hoge.c
The dll file is generated without difficulty! It can now be read on the Python side. I'm happy.
Recommended Posts