I need to generate two exe files that have some common source codes. What is the best way to do it with dub?
I tried to do like , but got error message about only one main function allowed.
Here is my 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"]
}]
}
Your
dub.json
will work, but you need to explicitly tell it to build one of the subpackages withdub build :App1
ordub build :App2
(where:App1
is a shortcut forcode1:App1
).Separate configurations may be more appropriate here:
dub build --config=App1
will produceapp1
,dub build --config=App2
will produceapp2
A plain
dub build
will default toApp1
.Note that you need
excludedSourceFiles
so dub doesn't see a duplicatemain
.The docs recommend against using subpackages for this purpose:
I realized you were using
dub.json
, so I put the json format above. For reference, here's thedub.sdl
format I posted earlier.