gpt4 book ai didi

c++ - 如何使用 Gradle DSL(领域特定语言)上的文档?

转载 作者:行者123 更新时间:2023-11-30 04:56:48 24 4
gpt4 key购买 nike

我目前正在设置我的混合 java/cpp 多模块 gradle 项目几天。虽然我承认我是 groovy &Co 的新手,但似乎每一步我都需要找到我正在尝试做的事情的确切示例,否则我无法进步。

问:谁能告诉我如何阅读这个 Gradle DSL page ?我正在尝试将我的库编译为仅静态(不共享),即使我使用了 baseName 并查看了 staticshared页面上记录的属性,我一生都无法理解如何使用它们。我的代码是:

components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}

baseName "mylibrary"
static "true" <-- what to write here??
shared "false" <-- ??
}
}

最佳答案

我环顾四周,看来你应该试试看:

components {
api(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "src/main/stuff"
include "**/*.cpp"
}
}
}

binaries {
all {
lib library: "mylibrary", linkage: "static"
}
}
}
}

编辑:

all 是来自 ModelMap 的方法接口(interface),由 getBinaries 返回方法。它说:将给定的操作应用于集合中的每个项目

ModelMap使用 BinarySpec作为参数 所以 all 的参数是一个 Action<BinarySpec>对象。

所以 Action类(功能接口(interface))定义了一种方法 execute(BinarySpec spec) .方法 lib 来自NativeBinarySpec

void lib(Object library)

Adds a library as input to this binary.

This method accepts the following types:

A NativeLibrarySpec
A NativeDependencySet
A Map containing the library selector.

The Map notation supports the following String attributes:

project: the path to the project containing the library (optional, defaults to current project)
library: the name of the library (required)
linkage: the library linkage required ['shared'/'static'] (optional, defaults to 'shared')

所以,总而言之,mylibrary被添加为所有二进制文件的输入。

关于c++ - 如何使用 Gradle DSL(领域特定语言)上的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52350347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com