DUB:创建两个具有共同代码库的可执行文件

标签 d dub

我需要生成两个具有一些通用源代码的 exe 文件。使用配音的最佳方法是什么?

我试过做 this , 但收到有关仅允许使用一个主要功能的错误消息。

这是我的 dub.json:

{
    "name": "code1",
    "authors": [ "Suliman" ],
    "description": "A minimal D application.",
    "copyright": "Copyright © 2016, Suliman",
    "license": "proprietary",
    "subPackages": [
    {
        "name": "App1",
        "targetName": "App1",
        "description": "App1",
        "targetType": "executable",
        "excludedSourceFiles" : ["source/App2/*"],
        "excludedSourceFiles" : ["source/app2.d"]
    },

    {
        "name": "App2",
        "targetName": "App2",
        "description": "App2",
        "targetType": "executable",
        "excludedSourceFiles" : ["source/App1/*"],
        "excludedSourceFiles" : ["source/app1.d"]
    }]
} 

最佳答案

你的 dub.json 可以工作,但你需要明确地告诉它构建一个 带有 dub build :App1dub build :App2 的子包(其中 :App1 是一个 code1:App1 的快捷方式。

单独的配置在这里可能更合适:

"configurations": [
    {
        "name": "App1",
        "targetType": "executable",
        "mainSourceFile": "source/app1.d",
        "excludedSourceFiles": [ "source/app2.d", "source/App2/*" ],
        "targetName": "app1"
    },
    {
        "name": "App2",
        "targetType": "executable",
        "mainSourceFile": "source/app2.d",
        "excludedSourceFiles": [ "source/app1.d", "source/App1/*" ],
        "targetName": "app2"
    }
]

dub build --config=App1 将生成 app1dub build --config=App2 将生成 app2

普通 dub build 将默认为 App1

请注意,您需要 excludedSourceFiles,这样 dub 就不会看到重复的 main

The docs反对 为此目的使用子包:

It is also possible to define the sub packages within the root package file, but note that it is generally discouraged to put the source code of multiple sub packages into the same source folder. Doing so can lead to hidden dependencies to sub packages that haven't been explicitly stated in the "dependencies" section. These hidden dependencies can then result in build errors in conjunction with certain build modes or dependency trees that may be hard to understand.

我发现你用的是dub.json,所以我把json格式放在上面。为了 引用,这是我之前发布的dub.sdl格式。

configuration "App1" {
    targetType "executable"
    mainSourceFile "source/app1.d"
    excludedSourceFiles "source/app2.d" "source/App2/*"
    targetName "app1"
}

configuration "App2" {
    targetType "executable"
    mainSourceFile "source/app2.d"
    excludedSourceFiles "source/app1.d" "source/App1/*"
    targetName "app2"
}

关于DUB:创建两个具有共同代码库的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35672681/

相关文章:

d - 配置 DUB 以使用 64 位编译器

pointers - 如何在 D 中声明一个指向非常量/可变数据的常量指针?

d - 如何将 dub.sdl 转换为 dub.json?

d - 为什么我的 dsfml 代码没有通过 dub 编译

d - 如何在 Dub 中添加和运行子包?

exception - 如何停止 Vibe.D 应用程序?

linux - SDL 窗口似乎被操作系统错误地标记为 'unresponsive'

d - D2 语言准备好用于生产了吗?

linux - 关闭第三方代码的单元测试执行