For a computation demonstration project in Linux and Python env, I need to call a C multiplication routine "matmult.c" but before I want to perform an important test if I could do another ctypes import from Windows. I have built a shared library named libdivide.so with MinGW (not MinGW-w64) and followed this post but without doing any configuration to indicate a compiler path to MinGW.
C:\base39\frede\Cpython_win32\setup.py
I really want to get some infos or some sites (I just read the ctypes official doc) to read to go further because my first question is: has anyone already tried this?
building firstly the shared lib and then run
python setup.py build_ext. In the meanwhile I will advance on Linux except if I have a return post.
My OS is Windows 10 64 bits.
Edit: I have installed MinGW on the root C:\ but the only time when I have tried to load a shared library from this compiler but outside msys.exe it was on another PC with Matlab R14(an eternity) and it had failed. Now I know that I would better try MinGW-w64 for R2021b but I could get the same error (below). My second question would be: do I need some extra knowledge about dll for getting this?
from distutils.core import setup, Extension
setup(name='divide',
version='1.0',
description='Python extension package for demo',
ext_modules=[Extension('divide', ['dividefunc.c'],include_dirs=['include'])],
packages=[''],
# fred yhe package is assumed to be at the root
package_dir={'': 'lib'},
#package_data = unused here
)
import ctypes
lib = ctypes.cdll.LoadLibrary('divide.so') #not sure
def divide_modulo(a,b):
div=ctypes.c_int(0)
rest=ctypes.c_int(0)
lib.divide_int(a,b, ctypes.byref(div), c_types.byref(rest))
return (div.value, rest.value)
#class DynamicArray(ctypes.Structure):
# _fields_ = [("n", ctypes.c_int), ("r", ctypes.POINTER(c_types.c_int))]
./include/dividefunc.h
./lib/libdivide.so
./source/
./setup.py
./dividepy.py
Many thanks
(base39) C:\base39\frede\Cpython_win32>python setup.py build_ext
running build_ext
building 'divide' extension
error: Unable to find vcvarsall.bat