I've got some problems with linking against a debug version of my lib. I use CMake to make a library:
project(myLib)
...
add_library(myLib SHARED ${SOURCES})
I launch the build two times to get a release and a debug version of my lib. Then I add 'd' suffix to the name of the debug lib and have myLib.dll
and myLibd.dll
.
In my app I explicitly link against the debug dll:
project(myApp)
add_executable(myApp WIN32 ${SOURCES})
target_link_libraries(myApp myLibd.dll)
The build finishes successfully, but when I open the resulting exe file with Dependency Walker I get an unresolved dependency to myLib.dll
file, even though the debug version (myLibd.dll
) is located in the same folder.
So, why does my app try to use the release version of my lib at runtime? And how do I properly link against the debug version?
It will now default to using a debug build if the source directory is a git clone, or a release build if not. It is also quite easy to customize its behavior according to the preferences of your project.
Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target's dependencies affect compilation of its own sources.
First, switch to CMake Targets View in the Solution Explorer window. Then, right-click on an executable and select Debug. This command automatically starts debugging the selected target based on your active configuration.
You should not rename the file manually. Use CMake's CMAKE_DEBUG_POSTFIX
variable or the DEBUG_POSTFIX
target property instead:
add_library(myLib SHARED ${SOURCES})
set_target_properties(mylib PROPERTIES DEBUG_POSTFIX "d")
[...]
add_executable(myApp WIN32 ${SOURCES})
target_link_libraries(myApp myLib)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With