windows using vcpkg: debug builds fail with LNK2005 (symbol already defined)
this is on windows 11 x64 with OpenCV installed statically via vcpkg and using the latest stable rustc (1.87.0).
i can run cargo build --release successfully, however with cargo build (i.e. debug build) it always fails because it finds the OpenCV symbols twice: once from the debug lib and once from the release lib, e.g.:
= note: opencv_core4.lib(matrix_expressions.cpp.obj) : error LNK2005: "public: __cdecl cv::MatExpr::MatExpr(class cv::Mat const &)" (??0MatExpr@cv@@QEAA@AEBVMat@1@@Z) already defined in opencv_core4d.lib(opencv_core4d.dll)␍
(there are a ton more of those, see the full output in the gist below)
i'm not sure why it tries to link against the release libs (e.g. opencv_core4.lib) as well as the debug lib (e.g. opencv_core4d.lib) during the debug build and i'm not sure whether this is a problem of opencv-rust or of vcpkg?
this is not specific to one project, i have this with all projects where i try to use opencv-vcpkg. i can e.g. reproduce this with my test project
build output (after cargo clean): https://gist.github.com/rursprung/b1b809520f39341ff7b2e30375db5d2d
As far as I can see the actual reason it links to the release OpenCV libraries is because the main program build instructs it to:
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-search=native=...\.vcpkg-clion\vcpkg\installed\x64-windows-static-md\lib
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-lib=opencv_aruco4
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-lib=opencv_bgsegm4
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-lib=opencv_bioinspired4
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-lib=opencv_calib3d4
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-lib=opencv_ccalib4
[rust-opencv-vcpkg 0.1.0] cargo:rustc-link-lib=opencv_core4
Why there is a mismatch in understanding whether we need to link release libraries or debug is something I would need to investigate, thanks for the report!