build: added DEBUG build guard (cv::debug_build_guard::_InputArray error LNK2019)#9161
Conversation
To prevent linkage of binary incompatible DEBUG/RELEASE binaries/runtimes
|
👍 |
|
I am using MSVS to compile a project in Release-With-Debug-Information (that is enabling the /Zi flag). I compiled OpenCV exactly the same way and I am linking to it statically. I get the error LNK2019 specified above. What am I doing wrong? |
|
@cdcseacave Please check for DEBUG / _DEBUG macros in your "Release-With-Debug-Information" build configuration. |
|
They are disabled, only NDEBUG is define |
|
This is very strange, because inner |
|
I found the issue, DEBUG is defined in one external logging library. It is a macro printing something to std::cout (which to be honest looks quite legit to me). Wouldn't be safer to change your check from |
|
I found a work around for this (maybe it will be helpful to others as well). Wrap the OpenCV includes with: |
|
Hi @alalek. I'm using CMake 3.9 and Visual Studio 2017. As far as I can tell, It seems to be a limitation of CMake, since Visual Studio does add the On the other hand, I can make a Pull Request if that's OK. Regards, |
|
@bblanchon Please check for "/MDd" compiler option in your debug build. Using MSVS headers widely uses |
|
You're right @alalek! I managed to build properly with "Debug" and "Release" configuration. "RelWithDebInfo" and "MinSizeRel" use the non-debug version of the runtime ( The solution is to map the project configurations to the imported library configurations: set_target_properties(opencv_highgui PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
)Do you mind if I make a PR? |
|
OpenCV supports Debug/Release only. We don't want to support other exotic build configurations (we will not test them or prepare binaries). Proposed solution with configuration mapping should help here. It should be added for all OpenCV targets somewhere here: |
|
What the heck is this? |
|
I confirm it breaks linking debug build of OpenCV4.0b (at least on MSVC 2015 x64). (cmake=3.12.3) |
|
@sylvain-bougnoux Can't reproduce with CMake 3.11.0:
|
|
My mistake, the cmake cache was probably scrambled. For some strange reasons, it worked in Release. Now cleaning the cache, both debug & release compile fine. |
|
I think that it's never the responsibility of a library to make sure it's not linked in a mixed bad way. If the developer can't figure that out, it's his problem. You should not break libraries because of this... |
|
@danielgindi You should select proper DEBUG OpenCV binary for your DEBUG builds.
Right. |
|
it's very common that a Debug config of Application is linked to release version of OpenCV. On Sourceforge, only release version of OpenCV is available for download, to get a debug build, it's required to build OpenCV from source, which is another pain. If you really want to promote the usage of Debug version of OpenCV, just release a debug version, much simpler. The error is reported very late at link phase, not build phase, as a very common error of I'm afraid it wasted more development time than it saved, at least for me. |
Don't know about Sourceforge, but on Github they do. I have official Windows packages sitting on my disk going back at least a decade and they all include a debug binary as well AFAICT. |
To prevent linkage of binary incompatible DEBUG/RELEASE binaries/runtimes.
resolves #5227
resolves #6070
resolves #5564
It is hard to debug this kind of issues. Application just crash / hangs without any useful information from debugger.
_GLIBCXX_DEBUGmacro).There is a special marker in these messages: debug_build_guard / cv::debug_build_guard::_InputArray .
If you see this then you should get debug version of OpenCV binaries or switch your application build mode to "release".
BTW, you can improve experience of "release builds" debugging by using of these safe hacks: