我需要生成两个具有一些通用源代码的 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"]
}]
}
最佳答案
你的 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"
}
]
dub build --config=App1
将生成 app1
,
dub 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/