Cannot compile betterC app in windows using stderr

kinke noone at nowhere.com
Thu Feb 3 19:55:06 UTC 2022


On Wednesday, 2 February 2022 at 20:58:25 UTC, Walter Bright 
wrote:
> On 2/2/2022 4:17 AM, kinke wrote:
>> On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:
>>> ```d
>>> else version (CRuntime_Microsoft)
>>> {
>>>     ///
>>>     shared FILE* stdin;  // = &__iob_func()[0];
>>>     ///
>>>     shared FILE* stdout; // = &__iob_func()[1];
>>>     ///
>>>     shared FILE* stderr; // = &__iob_func()[2];
>>> }
>>> ```
>>>
>>> shouldn't these variable declarations be `extern` ?
>> 
>> Nope, they are macros in the MSVC headers, no symbols are 
>> available. That's why druntime defines them and sets them up 
>> at startup, so they aren't available/linked with `-betterC`.
>
> The trouble is -betterC does not link with druntime, so it 
> can't find stderr. The solution is to make stderr a template, 
> so that no linking with druntime is necessary.

That's not a solution, but a hack. ;) - With at least 2 major 
problems:

* Template culling. If the compiler e.g. sees a stderr 
instantiation in druntime in the import graph, it may decide not 
to emit the stderr symbol into the betterC binary, assuming that 
druntime will be linked anyway.
* Potentially a DSO-local stderr symbol for each binary 
(executable or DLL/.so/.dylib), so that changing it in one DSO 
might not change it for the whole process.

There have been previous 'dummy-templatizations' in 
druntime/Phobos to work around missing symbols with -betterC. 
IMO, that's just patching over the cracks of the -betterC hack 
and pessimizing regular D, and in case it's not obvious, I'm 
definitely no fan of this. :)


More information about the Digitalmars-d mailing list