Jan-12-2023, 02:41 PM
Hello I wrote simple c extension module and assembled it with visual studio everything works
When i try to assemble it with mingw i am getting issue when i try to run my module.
platform Win10
mingw: 2013072200
python 3.11
cpython.c
When i try to assemble it with mingw i am getting issue when i try to run my module.
platform Win10
mingw: 2013072200
python 3.11
cpython.c
#include "stdio.h"
#include <Python.h>
static PyObject *
cpython1_print_info(PyObject *self, PyObject *args)
{
printf("vasia pupkin 2\n");
//print_info();
return Py_BuildValue("");
}
static PyMethodDef cpython1Methods[] = {
{"print_info", cpython1_print_info, METH_VARARGS, "call function from static lib which prints something"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef cpython1 =
{
PyModuleDef_HEAD_INIT,
"cpython1",
"cpython1 print_info",
-1, //global states
cpython1Methods
};
PyMODINIT_FUNC
PyInit_cpython2(void)
{
return PyModule_Create(&cpython1);
}setup.pyfrom setuptools import setup, Extension
module=Extension("cpython2",
sources=['src/cpython2.c'],
include_dirs=['src','lib'],
library_dirs=['lib', 'c:/Program Files (x86)/Windows Kits/10/Lib/10.0.22000.0/ucrt/x86/'],
libraries=['mylib_lib'],
extra_compile_args=["-m32"])
setup(name='cpython2',
version='1.0.1',
description='Python API for cpython1.c',
author='Vasia Pupkin',
author_email='[email protected]',
#ext_modules=[Extension('cpython1', ['src/cpython1.c'], include_dirs=['src'])],
ext_modules=[module],
py_modules=['cpython2']
)Whein i try to run module i see thisC:\Appl\test\mingw\cpython2\build\lib.win32-cpython-311>dir
Directory of C:\Appl\test\mingw\cpython2\build\lib.win32-cpython-311
01/12/2023 04:42 PM <DIR> .
01/12/2023 04:42 PM <DIR> ..
01/12/2023 04:42 PM 10,752 cpython2.cp311-win32.pyd
1 File(s) 10,752 bytes
2 Dir(s) 69,593,444,352 bytes free
C:\Appl\test\mingw\cpython2\build\lib.win32-cpython-311>python
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:43:28) [MSC v.1934 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cpython2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing cpython2: A dynamic link library (DLL) initialization routine failed.
>>>if run "python -vv" then output will look like this>>> import cpython2 # trying C:\Appl\test\mingw\cpython2\build\lib.win32-cpython-311\cpython2.cp311-win32.pyd Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 676, in _load_unlocked File "<frozen importlib._bootstrap>", line 573, in module_from_spec File "<frozen importlib._bootstrap_external>", line 1233, in create_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed ImportError: DLL load failed while importing cpython2: A dynamic link library (DLL) initialization routine failed. >>>
