【问题标题】:How to forward dependencies in Meson?如何在 Meson 中转发依赖项?
【发布时间】:2022-06-13 20:31:00
【问题描述】:

假设我有以下依赖链,依赖 A 依赖于 B,而 B 又依赖于 C。所有 3 个都指定为 dep 对象。

B 的头部包含 C 的头部。

我发现当我编译 A 时,即使 B 已经被列为依赖项,我也必须将 C 列为显式依赖项,否则 C 的标头在 A 的翻译单元中不可用。

如何指示介子在 B 用作依赖项的地方自动包含 C 的标头?

【问题讨论】:

    标签: c++ build-system meson-build


    【解决方案1】:

    我认为你需要使用 declare_dependency
    像这样的东西应该可以工作。

    C_dep = declare_dependency(include_directories : C_includes)
    B_dep = declare_dependency(include_directories : B_includes, dependencies : [C_dep])
    A_dep = static_library('a_lib', dependencies : [B_dep]) # or whatever your usecase is
    

    【讨论】:

      【解决方案2】:

      您必须通过 include_directories 指定您的 C 依赖项,其中包含标头路径:

      c_dep = declare_dependency(
        dependencies: c_lib,
        include_directories: include_directories(c_inc_dirs),
      )
      

      然后在你的 B 依赖中添加 C,像这样:

      b_deps = []
      b_deps += dependency('clib', fallback:['clib', 'c_dep'])
      
      b_dep = declare_dependency(
          link_with: b_lib,
          include_directories: b_inc_dirs,
          dependencies: b_deps)
      

      A 也应该给 B 添加正常的依赖,而不是给 C,因为 C 已经添加到 B 中了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-10
        • 2021-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多