Debug and Release Library Linking with CMAKE (VISUAL STUDIO)

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.

Leave a Comment