Friday, June 3, 2022

[SOLVED] CMake RelWithDebInfo links to Debug libs

Issue

I have a project which links to half a dozen libraries, among them OpenCV.
Since Release variant is crashing, while Debug is working fine (just a lot slower), I wanted to compile my project in RelWithDebInfo configuration.
However, Debug version of OpenCV libraries gets included instead of Release (OpenCV doesn’t have RelWithDebInfo variant). This causes linking errors such as:

opencv_core249d.lib(alloc.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MDd_DynamicDebug’ doesn’t match value ‘MD_DynamicRelease’ in MyProject.obj

How to solve this problem?


Solution

Solution: add to CMakeLists.txt, after the call to FIND_PACKAGE(OpenCV):

set_target_properties(${OpenCV_LIBS} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)


Answered By - Dženan
Answer Checked By - Dawn Plyler (WPSolving Volunteer)