Thread overview
native way to tell if output binary is library or executable?
Jan 18
Jack
Jan 18
Jack
January 18
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.
January 18
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.
January 18
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!