Debug build error: LNK1104: cannot open file 'python310_d.lib'

I’m trying to follow the documentation, but perhaps I’m missing some steps.
Building 4.5.5 with contrib with VS2022 17.1/17.3 (Also tried 2019) gives me the error

>LINK : fatal error LNK1104: cannot open file 'python310_d.lib'

It’s the only error, and the debug libs are located in %PythonPath%/lib, as I thought was the standard.

My simple CMakeLists.txt for the project,

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(opencv)

set(OPENCV_EXTRA_MODULES_PATH ../opencv_contrib-4.5.5/modules)
add_subdirectory(opencv-4.5.5)

The cmake build config gives me this warning, but otherwise looks fine:

[cmake] CMake Warning at opencv-4.5.5/cmake/OpenCVGenSetupVars.cmake:54 (message):
[cmake]   CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
[cmake]   directory
[cmake] Call Stack (most recent call first):
[cmake]   opencv-4.5.5/CMakeLists.txt:1035 (include)

Which is the block

if(DEFINED __python_path)  # Path to my python dir
  if(IS_ABSOLUTE "${__python_path}")  # This is the condition that triggers
    set(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${__python_path}")  # Changes path to "directory"??
    message(WARNING "CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install directory")
  else()
    ocv_path_join(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG}" "${__python_path}")
  endif()
else()
  if(DEFINED OPENCV_PYTHON3_INSTALL_PATH)
    ocv_path_join(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG}" "${OPENCV_PYTHON3_INSTALL_PATH}")
  else()
    set(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "python_loader_is_not_installed")
  endif()
endif()

I think this may be why my debug build of OpenCV does not work, testing with a sample program using highgui and imgproc.
The Release builds works just fine with no build errors.

Interestingly, a debug builds with opencv source include into the project like the answer to this topic works fine. It’s the same sample program I am testing.

EDIT: My CMakeLists.txt of the sample project:

cmake_minimum_required(VERSION 3.1.0)

project(VehicleComputerVision VERSION 0.1.0)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)

add_executable(VehicleComputerVision
    VehicleComputerVision.cpp
)
target_link_libraries(VehicleComputerVision
PRIVATE
    opencv_core
    opencv_highgui
    opencv_imgproc
)

Config runs fine, build runs fine, but a debug build run simply “fails”:

Loaded ...\VehicleComputerVision\build\bin\Debug\VehicleComputerVision.exe'. Symbols loaded.
Loaded 'C:\Windows\System32\ntdll.dll'. 
Loaded 'C:\Windows\System32\kernel32.dll'. 
Loaded 'C:\Windows\System32\KernelBase.dll'. 
Loaded 'C:\Windows\System32\msvcp140d.dll'. 
The program '[20472] VehicleComputerVision.exe' has exited with code -1073741515 (0xc0000135).

it’s looking for a debug build of python…

I wouldn’t recommend it. just do a release build.

I don’t know if there’s a way to have a debug build that uses a release python.

you could see if you can find a debug build of python.

I can build with the Release configuration fine.

But if I want to run debug of my own program while using OpenCV libs, I have to provide it with some openCV debug build of the libraries as well, since it will look for the libs in opencv4-5.5/lib/Debug, right?

(Also, I have the python debug libs installed, so I guess they should be found?)

that’s where my expertise ends. I prefer Python whenever possible and I’ve never looked into how to have my own C/C++ code debug-built while using release libraries. it might be easy to do, can’t tell. I hope someone else will take a look at this issue.

1 Like

If you have python installed for Visual Studio, its possible its not picking up your debug libs because cmake is using that version of python?

Have you tried modifying pyconfig.h as described here.

1 Like

You have to build python in debug and give lib path in cmake

-DPYTHON3_DEBUG_LIBRARY=“C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/libs/python39_d.lib”
and rebuild opencv

then if you are lucky may be you will able to debug…

1 Like

Thanks for your replies and help, all of you.
I tried the pyconfig.h hack, and after a complete rebuild of opencv I get no errors, but running a debug version my program still exits with an error code, so I reverted it again. Will keep the link, though, I haven’t found many people documenting newer builds of opencv, so that’s nice to have.

Laurent, it seems you are right, I thought the _d.lib would be enough, but most people having similar issues apparently have to build the python debug version as well. I might do that, or try to somehow include the release opencv libs into a debug project.