• <small id='Iw53Y'></small><noframes id='Iw53Y'>

    <legend id='Iw53Y'><style id='Iw53Y'><dir id='Iw53Y'><q id='Iw53Y'></q></dir></style></legend>
      <bdo id='Iw53Y'></bdo><ul id='Iw53Y'></ul>

      <tfoot id='Iw53Y'></tfoot>

      1. <i id='Iw53Y'><tr id='Iw53Y'><dt id='Iw53Y'><q id='Iw53Y'><span id='Iw53Y'><b id='Iw53Y'><form id='Iw53Y'><ins id='Iw53Y'></ins><ul id='Iw53Y'></ul><sub id='Iw53Y'></sub></form><legend id='Iw53Y'></legend><bdo id='Iw53Y'><pre id='Iw53Y'><center id='Iw53Y'></center></pre></bdo></b><th id='Iw53Y'></th></span></q></dt></tr></i><div id='Iw53Y'><tfoot id='Iw53Y'></tfoot><dl id='Iw53Y'><fieldset id='Iw53Y'></fieldset></dl></div>
      2. 调试和发布库链接与 CMAKE (VISUAL STUDIO)

        时间:2023-05-23

          1. <small id='nTf81'></small><noframes id='nTf81'>

            <i id='nTf81'><tr id='nTf81'><dt id='nTf81'><q id='nTf81'><span id='nTf81'><b id='nTf81'><form id='nTf81'><ins id='nTf81'></ins><ul id='nTf81'></ul><sub id='nTf81'></sub></form><legend id='nTf81'></legend><bdo id='nTf81'><pre id='nTf81'><center id='nTf81'></center></pre></bdo></b><th id='nTf81'></th></span></q></dt></tr></i><div id='nTf81'><tfoot id='nTf81'></tfoot><dl id='nTf81'><fieldset id='nTf81'></fieldset></dl></div>
            <tfoot id='nTf81'></tfoot><legend id='nTf81'><style id='nTf81'><dir id='nTf81'><q id='nTf81'></q></dir></style></legend>
              <bdo id='nTf81'></bdo><ul id='nTf81'></ul>
                  <tbody id='nTf81'></tbody>

                  本文介绍了调试和发布库链接与 CMAKE (VISUAL STUDIO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  已经有一个线程,但实际上并没有帮助.我希望能够链接例如 Foo.lib 用于 Release 配置和 Foo_d.lib 用于 Debug 配置,我怎样才能做到这一点?如果我这样做:

                  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?

                  非常感谢!

                  推荐答案

                  当你的库是项目的一部分或者你是使用 find_package 命令的配置模式导入它(参见 文档 和 example).如果你不能修改 3rd 方,它会产生 Config.cmake(它可能不使用 cmake 工具或者您不想这样做)答案是模拟这样的过程:

                  There is no problems when your library is a part of the project or you're importing it using config mode of find_package command (see documentation and example). In case you can't modify 3rd party so it will produce <package>Config.cmake (it may not use cmake tool or you don't want to do it) the answer is to emulate such process:

                  add_library(foo STATIC IMPORTED)
                  set_target_properties(foo PROPERTIES IMPORTED_LOCATION_DEBUG "/path/to/foo-d.lib")
                  set_target_properties(foo PROPERTIES IMPORTED_LOCATION_RELEASE "/path/to/foo.lib")
                  
                  target_link_libraries(MyEXE foo)
                  

                  请注意,与调试"/优化"功能不同,这种方法不仅限于调试/发布配置:

                  note that unlike "debug"/"optimized" feature such approach is not limited to Debug/Release configs:

                  set_target_properties(foo PROPERTIES IMPORTED_LOCATION_MINSIZEREL "/path/to/foo-small.lib")
                  

                  你还有一些好东西,比如INTERFACE_INCLUDE_DIRECTORIES:

                  also you've got some goodies like INTERFACE_INCLUDE_DIRECTORIES:

                  set_target_properties(foo PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "/path/to/foo/includes")
                  
                  include_directories("/path/to/foo/includes") # this line not needed
                  target_link_libraries(MyEXE foo) # this command will add "/path/to/foo/includes" for you
                  

                  和传递链接:

                  add_library(boo STATIC IMPORTED)
                  set_target_properties(boo PROPERTIES IMPORTED_LOCATION_DEBUG "/path/to/boo-d.lib")
                  set_target_properties(boo PROPERTIES IMPORTED_LOCATION_RELEASE "/path/to/boo.lib")
                  
                  add_library(foo STATIC IMPORTED)
                  set_target_properties(foo PROPERTIES IMPORTED_LOCATION_DEBUG "/path/to/foo-d.lib")
                  set_target_properties(foo PROPERTIES IMPORTED_LOCATION_RELEASE "/path/to/foo.lib")
                  
                  set_target_properties(foo PROPERTIES INTERFACE_LINK_LIBRARIES boo) # foo depends on boo
                  
                  target_link_libraries(MyEXE foo) # boo will be linked automatically
                  

                  当然,您可以使用常规的 cmake 命令,例如 find_libraryfind_package(... MODULE) 来估计位置,而不是对其进行硬编码.

                  Of course you can use regular cmake commands like find_library and find_package(... MODULE) to estimate locations instead of hardcoding them.

                  这篇关于调试和发布库链接与 CMAKE (VISUAL STUDIO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 Visual Studio 调试器与不使用调试器运行可执 下一篇:从 Intellisense 中隐藏 C++ 代码块

                  相关文章

                  最新文章

                  <small id='bbOR7'></small><noframes id='bbOR7'>

                    <tfoot id='bbOR7'></tfoot>
                  1. <i id='bbOR7'><tr id='bbOR7'><dt id='bbOR7'><q id='bbOR7'><span id='bbOR7'><b id='bbOR7'><form id='bbOR7'><ins id='bbOR7'></ins><ul id='bbOR7'></ul><sub id='bbOR7'></sub></form><legend id='bbOR7'></legend><bdo id='bbOR7'><pre id='bbOR7'><center id='bbOR7'></center></pre></bdo></b><th id='bbOR7'></th></span></q></dt></tr></i><div id='bbOR7'><tfoot id='bbOR7'></tfoot><dl id='bbOR7'><fieldset id='bbOR7'></fieldset></dl></div>

                    <legend id='bbOR7'><style id='bbOR7'><dir id='bbOR7'><q id='bbOR7'></q></dir></style></legend>
                        <bdo id='bbOR7'></bdo><ul id='bbOR7'></ul>