【问题标题】:DUB: Create two executable files with common code baseDUB:使用通用代码库创建两个可执行文件
【发布时间】:2016-02-27 17:04:24
【问题描述】:

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

我尝试像 那样做,但收到关于只允许一个主要功能的错误消息。

这是我的 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"]
    }]
} 

【问题讨论】:

    标签: d dub


    【解决方案1】:

    你的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"
    }
    

    【讨论】:

    • 似乎每次只编译一个应用程序。有没有办法同时编译多个目标? (就像 cmake 一样)。例如。我有一个游戏引擎,有许多不同的测试/演示/示例,我想检查所有内容(无需重新编译)。
    • Prokop,这仍在进行中,但是父项目中的 targetType "none" 可能对您有用,但恐怕它仅适用于子包。我自己还没有尝试过。有关详细信息,请参阅 github.com/dlang/dub/pull/1364 及其引用的 PRs
    猜你喜欢
    • 2021-08-02
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    相关资源
    最近更新 更多