www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - native way to tell if output binary is library or executable?

reply Jack <jckj33 gmail.com> writes:
I know I can set version but I'd looking for a native way, if 
any, to do that. Is possible to tell if output binary is library 
or executable at compile time? then I'd call different version of 
a function.
Jan 17 2021
parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 18 January 2021 at 02:24:59 UTC, Jack wrote:
 I know I can set version but I'd looking for a native way, if 
 any, to do that. Is possible to tell if output binary is 
 library or executable at compile time? then I'd call different 
 version of a function.
Add `-version=library` to your compiler flags for the library and `-version=executable` to your compiler flags for the executable. Then, in the code, you can check for `version (library)` and `version (executable)`. Before you ask: no, there is no "more native" way to do this, because there is actually no difference in how the code is compiled between the two versions. The distinction between library and executable is only made when the compiled code is linked.
Jan 17 2021
parent Jack <jckj33 gmail.com> writes:
On Monday, 18 January 2021 at 03:30:56 UTC, Paul Backus wrote:
 On Monday, 18 January 2021 at 02:24:59 UTC, Jack wrote:
 I know I can set version but I'd looking for a native way, if 
 any, to do that. Is possible to tell if output binary is 
 library or executable at compile time? then I'd call different 
 version of a function.
Add `-version=library` to your compiler flags for the library and `-version=executable` to your compiler flags for the executable. Then, in the code, you can check for `version (library)` and `version (executable)`. Before you ask: no, there is no "more native" way to do this, because there is actually no difference in how the code is compiled between the two versions. The distinction between library and executable is only made when the compiled code is linked.
I'll really use this then. Thanks!
Jan 18 2021