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

我尝试做像d - DUB:使用通用代码库创建两个可执行文件-LMLPHP一样,但是收到有关仅允许一个主要功能的错误消息。

这是我的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(其中:App1code1: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建议反对
为此目的使用子包:



我意识到您使用的是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"
}

10-07 15:21