Bug 19933 – MSVC: Undefined std{in,out,err} with -betterC

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2019-06-02T04:00:55Z
Last change time
2022-02-14T09:34:37Z
Keywords
pull
Assigned to
No Owner
Creator
SrMordred

Comments

Comment #0 by patric.dexheimer — 2019-06-02T04:00:55Z
Not only stdout, (stderr too, maybe more) Window 10 DMD D Compiler v2.086.0 LLVM D compiler (1.16.0-beta2) import core.stdc.stdio; extern(C) void main() { fprintf(stdout , "testing\n"); } //dub run --compiler=dmd --arch=x86_64 /* Program exited with code -1073740777 */ //dub run --compiler=ldc2 --arch=x86_64 /* lld-link: error: undefined symbol: stdout (...) */
Comment #1 by kinke — 2021-01-10T12:32:06Z
Quoting myself from https://github.com/ldc-developers/ldc/issues/3640#issuecomment-757464048: The MSVC runtime doesn't feature these symbols; MS defines them as macros, whereas druntime defines and sets them at startup for convenience. [And druntime of course isn't linked with -betterC.]
Comment #2 by kinke — 2021-01-10T12:55:16Z
Just noticed that the OP hasn't used -betterC, but a C main, thus skipping the druntime initialization (incl. setting std{in,out,err}). With LDC v1.25, there's no linker error anymore, but the expected segfault as with DMD.
Comment #3 by dkorpel — 2021-01-11T13:59:42Z
*** Issue 20532 has been marked as a duplicate of this issue. ***
Comment #4 by ryuukk.dev — 2021-02-26T22:41:04Z
I just got hit by this, using -betterC There are no errors, it just crash The solution is to init windows runtime, but how to do that? Shouldn't the solution be simpler? the experience as a result is very poor
Comment #5 by ryuukk.dev — 2021-02-26T22:45:22Z
I feel like the "Important" should be changed since it just crashes without any hints on how to solve the issue
Comment #6 by ryuukk.dev — 2021-02-26T22:58:57Z
Could https://github.com/dlang/druntime/blob/master/src/rt/msvc.d be moved to src/core? So everyone could just call: init_msvc()
Comment #7 by dlang-bot — 2022-02-12T11:19:39Z
@rainers created dlang/druntime pull request #3740 "fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC" fixing this issue: - fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC moved C runtime check into template function https://github.com/dlang/druntime/pull/3740
Comment #8 by dlang-bot — 2022-02-14T09:34:37Z
dlang/druntime pull request #3740 "fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC" was merged into master: - e7e6800babed4ff51b6c3b57dfa7e54cb76247f7 by Rainer Schuetze: fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC made stdin/out/err template function return value https://github.com/dlang/druntime/pull/3740