DUB specify version identifier on command line?

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 7 18:15:00 PST 2017


On Tuesday, 7 March 2017 at 22:30:30 UTC, XavierAP wrote:
> I'm talking about the conditional compilation keyword 
> "version", not about version strings. I've looked in DUB's help 
> and reference [1][2] but can't seem to find how to solve my 
> problem. On the command line it seems to be possible to specify 
> debug identifiers, but not version identifiers. [3]
>
> It came up while trying to do something specific, so I'll 
> explain this. I'm learning and trying things, and I was playing 
> with dlib.core.memory. Before moving to the next thing I wanted 
> to try printMemoryLog(). This outputs memory debugging info, 
> only when compiled with version(MemoryDebug) [3].
>
> I'm working with Visual D. However for 3rd party package 
> dependencies it's simpler to compile them with dub, and have VS 
> find the lib for my client project. Without the version 
> identifier, my program works: compiles, links to dlib, and runs 
> ok. Then I instruct VS to define version(MemoryDebug) for some 
> configuration. No matter how I re-run dub to build dlib, I get 
> linking errors from the additional functions defined in the 
> imported dlib source which aren't found in the binary lib.
>
> I guess it's also possible to specify this by adding to the 
> dub.json file [2], but for me it's more flexible if I can leave 
> it alone and compile different versions from the command line 
> alone. But if the json is the only way please let me know. 
> Otherwise what am I missing? Thanks in advance.
>
>
> [1] http://code.dlang.org/docs/commandline#build
> [2] http://code.dlang.org/package-format?lang=json#version-specs
> [3] https://dlang.org/spec/version.html#DebugCondition
> [4] 
> https://github.com/gecko0307/dlib/blob/master/dlib/core/memory.d

Setting version identifiers is done by the `-version=ident` 
command line flag (this is equivalent to `version = ident` at 
source level) .
This should therefore be settable by the "dflags" dub 
configuration setting.

The way I would do it would be to have a custom configuration 
that sets "dflags" : [ "other normal flags", "-version= 
MemoryDebug"]

and then build the MemoryDebug dub configuration.

Hope that makes sense.


More information about the Digitalmars-d-learn mailing list