Issues linking nanobind extension on Windows in Debug mode (VS wants to linke the release lib of Python). #795
Replies: 4 comments 2 replies
-
I think the import declaration is in the Python headers ( |
Beta Was this translation helpful? Give feedback.
-
In my experience, using a Release build of Python works with extension modules with Debug symbols. During debugging in C++, you will only stop at your own written code (including code from nanobind). |
Beta Was this translation helpful? Give feedback.
-
I'm in the same boat as @KerstinKeller, in that my Visual Studio project is failing to build a Debug module with the same error: LINK : fatal error LNK1104: cannot open file 'python3.lib' (I'm targeting the Stable API, hence python3.lib instead of 312.lib) I'm assuming that something in CMake isn't connecting the release settings of FindPython properly to the Debug config of our module target? |
Beta Was this translation helpful? Give feedback.
-
Note: we may be getting tripped up by Python itself rather than nanobind.... I found this in the Python headers (pyconfig.h): /* For an MSVC DLL, we can nominate the .lib files used by extensions */
#ifdef MS_COREDLL
# if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
/* not building the core - must be an ext */
# if defined(_MSC_VER)
/* So MSVC users need not specify the .lib
file in their Makefile (other compilers are
generally taken care of by distutils.) */
# if defined(_DEBUG)
# pragma comment(lib,"python312_d.lib")
# elif defined(Py_LIMITED_API)
# pragma comment(lib,"python3.lib")
# else
# pragma comment(lib,"python312.lib")
# endif /* _DEBUG */
# endif /* _MSC_VER */
# endif /* Py_BUILD_CORE */
#endif /* MS_COREDLL */ This code looks blatantly wrong to me: the debug check should allow for Py_LIMITED_API and link to pyton3_d.lib. I can see that my Visual Studio linker settings are correct in Debug, that is indeed trying to link to: python3_d.lib |
Beta Was this translation helpful? Give feedback.
-
So we're building Python extensions for our library with nanobind.
Now, since I needed to debug some things, I wanted to build the debug version of the extension.
The debug version of Python is installed and available.
However VS gives me a linker error.
It complains:
First strange thing: it looks for the non-debug lib, even though this is a debug build.
Second strange thing: This linker argument is nowhere to be found in the generated Visual Studio project files!
This is the search output through the project files:
I was searching through our code and pybind code for linker pragmas, nothing to be found. So I am officially out of ideas and wanted to ask if anyone has run into the problem or has some other tips where I could take a look.
Beta Was this translation helpful? Give feedback.
All reactions