There was already a Thread which did not help really. I want to be able to link for example Foo.lib for Release Config and Foo_d.lib for Debug Config , how can I achieve this? If I do this:
target_link_libraries(MyEXE debug Foo_d) target_link_libraries(MyEXE optimized Foo)
then I have both libraries in my project for the debug config? Why is there no Release option?
Thanks alot!
We can use CMAKE_BUILD_TYPE to set the configuration type: cd debug cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . cd ../release cmake -DCMAKE_BUILD_TYPE=Release ..
You can also start a debug session from Solution Explorer. 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.
CMake refers to different build configurations as a Build Type. Suggested build types are values such as Debug and Release, but CMake allows any type that is supported by the build tool.
exerpt: "RelwithDebInfo is quite similar to Release mode. It produces fully optimized code, but also builds the program database, and inserts debug line information to give a debugger a good chance at guessing where in the code you are at any time."
target_link_libraries takes a list, you don't need to call it twice. The following will work:
target_link_libraries(MyEXE debug Foo_d optimized Foo)
And to answer a question asked in the comments of another answer, working with multiple libraries works like so:
target_link_libraries(MyEXE debug Foo1_d optimized Foo1 debug Foo2_d optimized Foo2)
Note that if you also build the library as part of the CMake project, you don't need to specify debug or optimized. CMake will choose the right one for you.
The solution is:
SET(LINK_LIBRARY optimized Foo debug Foo_d) target_link_libraries(MyEXE ${LINK_LIBRARY})
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