DUB:使用公共代码库创建两个可执行文件

Dmi*_*kov 2 d dub

我需要生成两个具有一些常见源代码的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"]
    }]
} 
Run Code Online (Sandbox Code Playgroud)

rco*_*rre 7

您的dub.json工作将会起作用,但您需要明确告诉它使用dub build :App1或构建其中一个子包dub 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"
    }
]
Run Code Online (Sandbox Code Playgroud)

dub build --config=App1会产生app1, dub build --config=App2会产生app2

普通dub build将默认为App1.

请注意,你需要excludedSourceFiles这样dub看不到重复main.

文档建议不要为此目的使用子包:

也可以在根包文件中定义子包,但请注意,通常不鼓励将多个子包的源代码放在同一个源文件夹中.这样做会导致对"依赖项"部分中未明确声明的子包的隐藏依赖性.然后,这些隐藏的依赖关系可能导致构建错误以及可能难以理解的某些构建模式或依赖关系树.

我意识到你正在使用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"
}
Run Code Online (Sandbox Code Playgroud)