python-cffi / cffi

A Foreign Function Interface package for calling C libraries from Python.
https://cffi.readthedocs.io/en/latest/
Other
114 stars 41 forks source link

cffi does not link library with -lpython3 on Windows with mingw32-x64 #61

Closed genotrance closed 7 months ago

genotrance commented 7 months ago

Using cffi to generate a wrapper for libcurl. On Windows, cffi links with -lpython312 for mingw and so the build does not work on other versions of Python.

gcc -shared -s build\temp.win-amd64-cpython-312\Release\build\temp.win-amd64-cpython-312\release\_libcurl_cffi.o build\temp.win-amd64-cpython-312\Release\build\temp.win-amd64-cpython-312\release\_libcurl_cffi.def -LE:\libs\x86_64-windows -LC:\Users\user\AppData\Local\Temp\Mxt236\var\log\xwin\build-env-ywcrviwm\libs -LC:\Users\user\scoop\apps\python\current\libs -LC:\Users\user\scoop\apps\python\current -LC:\Users\user\AppData\Local\Temp\Mxt236\var\log\xwin\build-env-ywcrviwm\PCbuild\amd64 -lcurl -lpython312 -lvcruntime140 -o build\lib.win-amd64-cpython-312\_libcurl_cffi.pyd

Simply changing the -lpython312 to -lpython3 fixes the issue. I'm not sure where this command gets generated but presuming this repo is a good place to start.

Build command line is as follows:

python3 -m build -w . -C="--build-option=build" -C="--build-option=--compiler" -C="--build-option=mingw32" -C="--build-option=bdist_wheel" -C="--build-option=--py-limited-api" -C="--build-option=cp32"
arigo commented 7 months ago

The command is generated by setuptools. I don't know setuptools very well, particularly nowadays, and I have no experience with mingw32-x64. I fear you need to dig into it on your system to figure out how exactly the command line is generated, but to me it looks like a setuptools bug if it produces -lpython312 when you say --build-option=--py-limited-api explicitly.

genotrance commented 7 months ago

Closing since not cffi issue.