DUB:使用公共代码库创建两个可执行文件
我需要生成两个exe文件,有一些共同的源代码。使用dub的最佳方式是什么 我试图这样做,但只得到一个主函数允许的错误消息 这是我的dub.json:DUB:使用公共代码库创建两个可执行文件,d,dub,D,Dub,我需要生成两个exe文件,有一些共同的源代码。使用dub的最佳方式是什么 我试图这样做,但只得到一个主函数允许的错误消息 这是我的dub.json: { "name": "code1", "authors": [ "Suliman" ], "description": "A minimal D application.", "copyright": "Copyright © 2016, Suliman", "license": "proprietary",
{
"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
是
代码1:App1的快捷方式
在这里,单独的配置可能更合适:
“配置”:[
{
“名称”:“App1”,
“targetType”:“可执行文件”,
“mainSourceFile”:“source/app1.d”,
“排除源文件”:[“source/app2.d”,“source/app2/*”],
“targetName”:“app1”
},
{
“名称”:“App2”,
“targetType”:“可执行文件”,
“mainSourceFile”:“source/app2.d”,
“排除源文件”:[“source/app1.d”,“source/app1/*”],
“targetName”:“app2”
}
]
dub build--config=App1
将生成App1
,
dub build--config=App2
将生成App2
普通的dub构建将默认为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"
}
似乎每次只编译一个应用程序。有没有一种方法可以同时编译多个目标?(与cmake类似)。例如,我有一个游戏引擎,有许多不同的测试/演示/示例,我想检查全部(无需重新编译)。Prokop,这仍然是一项正在进行的工作,但父项目中的targetType“none”可能对您有用,但恐怕它只适用于子包。我自己还没有试过。有关更多详细信息,请参阅及其参考PRs