I have built a cython package on windows using mingw.
Everything was fine, the only warnings i got during the compilation were:
Mylib\__init__.c: In function '__Pyx_ImportType': \__init__.c:126091:13: warning: unknown conversion type character 'z' in format [-Wformat=] 126091 | "%s.%s size changed, may indicate binary incompatibility. " | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \__init__.c:126092:24: note: format string is defined here 126092 | "Expected %zd from C header, got %zd from PyObject", | ^ \__init__.c:126091:13: warning: unknown conversion type character 'z' in format [-Wformat=] 126091 | "%s.%s size changed, may indicate binary incompatibility. " | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \__init__.c:126092:47: note: format string is defined here 126092 | "Expected %zd from C header, got %zd from PyObject", | ^ \__init__.c:126091:13: warning: too many arguments for format [-Wformat-extra-args] 126091 | "%s.%s size changed, may indicate binary incompatibility. "but for the moment, since the compilation was ok (Only these warnings and no errors), i decided to test the library built in cython installing via pip the .whl package that was generated.
The rest of the output of the compilation is the following:
writing build\temp.win-amd64-3.8\Release\mylib\mylib.cp38-win_amd64.def creating build\lib.win-amd64-3.8 D:\mingw64\mingw64\bin\gcc.exe -shared -s build\temp.win-amd64-3.8\Release\mylib\__init__.o build\temp.win-amd64-3.8\Release\mylib\mylib.cp38-win_amd64.def -L./ -LC:\Users\Utente\AppData\Local\Programs\Python\Python38\libs -LC:\Users\Utente\AppData\Local\Programs\Python\Python38\PCbuild\amd64 -llmylib -lpython38 -lvcruntime140 -o build\lib.win-amd64-3.8\mylib.cp38-win_amd64.pyd -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive "-L ." installing to build\bdist.win-amd64\wheel running install running install_lib creating build\bdist.win-amd64 creating build\bdist.win-amd64\wheel copying build\lib.win-amd64-3.8\mylib.cp38-win_amd64.pyd -> build\bdist.win-amd64\wheel\. running install_egg_info Copying Mylib.egg-info to build\bdist.win-amd64\wheel\.\Mylib-1.0.0-py3.8.egg-info running install_scripts adding license file "LICENSE" (matched pattern "LICEN[CS]E*") creating build\bdist.win-amd64\wheel\Mylib-1.0.0.dist-info\WHEEL creating 'dist\Mylib-1.0.0-cp38-cp38-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it adding 'mylib.cp38-win_amd64.pyd' adding 'mylib-1.0.0.dist-info/LICENSE' adding 'mylib-1.0.0.dist-info/METADATA' adding 'mylib-1.0.0.dist-info/WHEEL' adding 'mylib-1.0.0.dist-info/top_level.txt' adding 'mylib-1.0.0.dist-info/RECORD' removing build\bdist.win-amd64\wheel c:\users\utente\desktop\mylib-main\.eggs\wheel-0.37.1-py3.8.egg\wheel\bdist_wheel.py:80: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect if get_flag('Py_DEBUG',Now, i moved to dist/ and i run:
py -3.8 -m pip install Mylib-1.0.0-cp38-cp38-win_amd64.whlEverything was fine. I tapped:
py -3.8 -m pip show MylibAnd the output was:
Name: Mylib Version: 1.0.0 Summary: My library Home-page: https://github.com/Mylib Author: Me Author-email: M...@gmail.com License: UNKNOWN Location: c:\users\utente\appdata\local\programs\python\python38\lib\site-packages Requires: Required-by:Now, i moved to c:\users\utente\appdata\local\programs\python\python38\lib\site-packages and i saw:
a .PYD file: mylib.cp38-win_amd64 and a directory: mylib.cp38-win_amd64
Inside mylib.cp38-win_amd64 there are only these files:
INSTALLER.txt
METADATA.txt
LICENSE.txt
RECORD.txt
WHEEL.txt
When i run on python3.8:
import mylibthis error occurs:
"ImportError: DLL load failed while importing mylib: The specified procedure could not be found."I tried to run from the same directory of the pyd file. Same error. I also tried to import the path with:
import mysys sys.path.append('directory of the pyd')Again same error. For what i have read there could be a problem with other dll dependencies. So, i used dumpbin on the pyd and this was the output:
File Type: DLL Image has the following dependencies: python38.dll libmylib.dll KERNEL32.dll msvcrt.dll Summary 1000 .CRT 1000 .bss 6000 .data 1000 .edata 4000 .idata 2000 .pdata 5000 .rdata 1000 .reloc 1000 .rsrc 51000 .text 1000 .tls 2000 .xdataIf the problem is a problem of other dll dependencies i just tought that i needed to import the dlls paths. So ,as suggested by fix pyd with other dependencies i used these commands before importing mylib:
import os os.add_dll_directory('directory of all the dlls previously showed')But again, same error, so the problem is not a problem of other dll dependencies.
The only thing i can imagine this problem come from is the warnings previously showed. And in particular the last line of the compilation:
c:\users\utente\desktop\mylib-main\.eggs\wheel-0.37.1-py3.8.egg\wheel\bdist_wheel.py:80: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect if get_flag('Py_DEBUG',That could cause the fact that, maybe (?), the library should be imported in debug mode (?), and so the pyd file (for what i have read) should have the signature mylib_d.pyd(?). But i tried to rename it in this way and it seems it does not work either.
NOTE: On unix i was able to cythonize everything and import mylib in python.