• <legend id='aA33H'><style id='aA33H'><dir id='aA33H'><q id='aA33H'></q></dir></style></legend>

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

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

        如何在 cmake 中添加库路径?

        How do I add a library path in cmake?(如何在 cmake 中添加库路径?)

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

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

        1. <tfoot id='C65Qb'></tfoot>

            1. <legend id='C65Qb'><style id='C65Qb'><dir id='C65Qb'><q id='C65Qb'></q></dir></style></legend>
                  <bdo id='C65Qb'></bdo><ul id='C65Qb'></ul>
                    <tbody id='C65Qb'></tbody>
                  本文介绍了如何在 cmake 中添加库路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的项目中有 2 个文件夹inc"和lib",它们分别具有标头和静态库.我如何告诉 cmake 分别使用这 2 个目录进行包含和链接?

                  I have 2 folders "inc" and "lib" in my project which have headers and static libs respectively. How do I tell cmake to use those 2 directories for include and linking respectively?

                  推荐答案

                  最简单的方法是添加

                  include_directories(${CMAKE_SOURCE_DIR}/inc)
                  link_directories(${CMAKE_SOURCE_DIR}/lib)
                  
                  add_executable(foo ${FOO_SRCS})
                  target_link_libraries(foo bar) # libbar.so is found in ${CMAKE_SOURCE_DIR}/lib
                  

                  不向每个编译器调用添加 -I 和 -L 标志的现代 CMake 版本将使用导入的库:

                  The modern CMake version that doesn't add the -I and -L flags to every compiler invocation would be to use imported libraries:

                  add_library(bar SHARED IMPORTED) # or STATIC instead of SHARED
                  set_target_properties(bar PROPERTIES
                    IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/lib/libbar.so"
                    INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include/libbar"
                  )
                  
                  set(FOO_SRCS "foo.cpp")
                  add_executable(foo ${FOO_SRCS})
                  target_link_libraries(foo bar) # also adds the required include path
                  

                  如果设置 INTERFACE_INCLUDE_DIRECTORIES 没有添加路径,旧版本的 CMake 也允许您使用 target_include_directories(bar PUBLIC/path/to/include).但是,此不再适用于 CMake 3.6 或更高版本.

                  If setting the INTERFACE_INCLUDE_DIRECTORIES doesn't add the path, older versions of CMake also allow you to use target_include_directories(bar PUBLIC /path/to/include). However, this no longer works with CMake 3.6 or newer.

                  这篇关于如何在 cmake 中添加库路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                  <i id='mCrqU'><tr id='mCrqU'><dt id='mCrqU'><q id='mCrqU'><span id='mCrqU'><b id='mCrqU'><form id='mCrqU'><ins id='mCrqU'></ins><ul id='mCrqU'></ul><sub id='mCrqU'></sub></form><legend id='mCrqU'></legend><bdo id='mCrqU'><pre id='mCrqU'><center id='mCrqU'></center></pre></bdo></b><th id='mCrqU'></th></span></q></dt></tr></i><div id='mCrqU'><tfoot id='mCrqU'></tfoot><dl id='mCrqU'><fieldset id='mCrqU'></fieldset></dl></div>
                    <tbody id='mCrqU'></tbody>

                  • <legend id='mCrqU'><style id='mCrqU'><dir id='mCrqU'><q id='mCrqU'></q></dir></style></legend>

                    <tfoot id='mCrqU'></tfoot>

                      • <bdo id='mCrqU'></bdo><ul id='mCrqU'></ul>
                      • <small id='mCrqU'></small><noframes id='mCrqU'>