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.jsonwill work, but you need to explicitly tell it to build one of the subpackages withdub build :App1ordub build :App2(where:App1is a shortcut forcode1:App1).Separate configurations may be more appropriate here:
dub build --config=App1will produceapp1,dub build --config=App2will produceapp2A plain
dub buildwill default toApp1.Note that you need
excludedSourceFilesso 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.sdlformat I posted earlier.