1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

Merge pull request #29309 from varun-jaiswal17:fix_dll_mismatch

Fix ONNXRuntime dll path mismatch #29309

**1. C2664 build error in `net_impl_backend.cpp`**
`EnableProfiling()` expects `const wchar_t*` on Windows (`ORTCHAR_T`), but was passed `const char*`. 

Fixed by converting to `std::wstring`, as suggested in #29278 

---

**2. Wrong ORT DLL loaded at runtime (`modules/dnn/CMakeLists.txt`)**
With `DOWNLOAD_ONNXRUNTIME=ON`, the DLL glob only searched `bin/` but the downloaded package places DLLs in `lib/`. This left the build tree with no ORT DLL, causing Windows to fall back to the stale `System32\onnxruntime.dll` (1.17.1), crashing against the ORT 1.25.1 API. 

Fixed by adding `lib/` as fallback and staging DLLs into the build bin directory at configure time.

Closes : #29278 

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Varun Jaiswal
2026-06-16 21:24:18 +05:30
committed by GitHub
parent 3f45dab070
commit 555f0901a3
2 changed files with 19 additions and 0 deletions
+14
View File
@@ -340,9 +340,23 @@ if(WITH_ONNXRUNTIME)
if(WIN32) if(WIN32)
if(ONNXRT_ROOT_DIR) if(ONNXRT_ROOT_DIR)
file(GLOB _ort_runtime_libs "${ONNXRT_ROOT_DIR}/bin/onnxruntime*.dll") file(GLOB _ort_runtime_libs "${ONNXRT_ROOT_DIR}/bin/onnxruntime*.dll")
if(NOT _ort_runtime_libs)
file(GLOB _ort_runtime_libs "${ONNXRT_ROOT_DIR}/lib/onnxruntime*.dll")
endif()
endif() endif()
if(_ort_runtime_libs) if(_ort_runtime_libs)
install(FILES ${_ort_runtime_libs} DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs) install(FILES ${_ort_runtime_libs} DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs)
foreach(_ort_dll ${_ort_runtime_libs})
if(MSVC_IDE)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_ort_dll}" "${EXECUTABLE_OUTPUT_PATH}/Release/"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_ort_dll}" "${EXECUTABLE_OUTPUT_PATH}/Debug/")
elseif(MSVC AND (CMAKE_GENERATOR MATCHES "Visual"))
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_ort_dll}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/")
else()
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_ort_dll}" "${EXECUTABLE_OUTPUT_PATH}/")
endif()
endforeach()
endif() endif()
elseif(APPLE) elseif(APPLE)
if(ONNXRT_ROOT_DIR) if(ONNXRT_ROOT_DIR)
+5
View File
@@ -96,7 +96,12 @@ void Net::Impl::finalizeOrt()
ort_profile_data.clear(); ort_profile_data.clear();
if (profilingMode != DNN_PROFILE_NONE) { if (profilingMode != DNN_PROFILE_NONE) {
ort_profile_path_prefix = cv::tempfile("opencv_ort_profile_"); ort_profile_path_prefix = cv::tempfile("opencv_ort_profile_");
#ifdef _WIN32
std::wstring w_profile_path(ort_profile_path_prefix.begin(), ort_profile_path_prefix.end());
opts.EnableProfiling(w_profile_path.c_str());
#else
opts.EnableProfiling(ort_profile_path_prefix.c_str()); opts.EnableProfiling(ort_profile_path_prefix.c_str());
#endif
} }
#ifdef _WIN32 #ifdef _WIN32