You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_testcapi fails to link on single-config generators: cannot open file 'python3.lib' (LNK1104) #452
On Windows, building with a single-config generator (Ninja, NMake Makefiles) fails while linking the _testcapi extension:
[721/737] Linking C shared library Lib\lib-dynload\_testcapi.pyd
FAILED: Lib/lib-dynload/_testcapi.pyd libs/_testcapi.lib
LINK : fatal error LNK1104: cannot open file 'python3.lib'
Multi-config generators (Visual Studio) are unaffected, which is why this has gone unnoticed.
Cause
_testcapi contains translation units compiled with Py_LIMITED_API (Modules/_testcapi/vectorcall_limited.c, heaptype_relative.c). PC/pyconfig.h then emits an auto-link directive for the stable-ABI import library:
$<CONFIG> expands on every generator, but only multi-config generators additionally append the configuration to a target's archive output directory. libpython3-shared sets LIBRARY_OUTPUT_DIRECTORY and RUNTIME_OUTPUT_DIRECTORY but no ARCHIVE_OUTPUT_DIRECTORY (cmake/libpython/CMakeLists.txt), so its import library falls back to the target's own binary directory — CMakeBuild/libpython, set by add_subdirectory(cmake/libpython CMakeBuild/libpython) at CMakeLists.txt:637.
Producer and consumer therefore disagree by exactly one directory level:
path
where python3.lib is actually written
<build>/CMakeBuild/libpython/python3.lib
where target_link_directories points
<build>/CMakeBuild/libpython/Release/ (does not exist)
Observed on disk in a failing build:
$ ls <build>/CMakeBuild/libpython/
CMakeFiles/ python3.lib <-- the file
$ ls <build>/CMakeBuild/libpython/Release
ls: cannot access ...: No such file or directory
The offending line was introduced by 5d016e6 ("test_testcapi: Fix build ensuring python3.lib is found", 2025-05-27) and is still present on master (1b1862a).
Reproducer
Any WIN32 build with a single-config generator and extension_testcapi enabled:
Activity