digitalmars.D.learn - Why does calling a struct constructor generate linker errors when
- Stijn (22/22) Dec 23 2017 https://dlang.org/spec/betterc.html doesn't mention struct
- rikki cattermole (3/31) Dec 23 2017 new uses GC.
- Stijn (4/8) Dec 23 2017 Oh I see, simply removing 'new' solves the problem. I've a C#
- rikki cattermole (5/14) Dec 23 2017 Yeah new = memory allocation.
- Stijn (8/12) Dec 23 2017 I'm using -betterC on purpose, doing bare-metal development. Had
https://dlang.org/spec/betterc.html doesn't mention struct constructors not working, but I'm getting linker errors when trying to call a struct constructor. Consider the following program betterc.d struct foo { } extern(C) void main() { auto bar = new foo(); } Compile with: dmd -c -m32 betterc.d -betterC Link with: gcc -m32 betterc.o -Wl,--build-id=none -nostdlib -o "betterc.bin" Linker output: betterc.o: In function `main': betterc.d:(.text.main[main]+0xa): undefined reference to `_d_newitemT' betterc.o:(.data._D22TypeInfo_S7betterc3foo6__initZ+0x0): undefined reference to `_D15TypeInfo_Struct6__vtblZ' collect2: error: ld returned 1 exit status Is there a mistake in my code, or is the documentation lacking?
Dec 23 2017
On 24/12/2017 1:20 AM, Stijn wrote:https://dlang.org/spec/betterc.html doesn't mention struct constructors not working, but I'm getting linker errors when trying to call a struct constructor. Consider the following program betterc.d struct foo { } extern(C) void main() { auto bar = new foo(); } Compile with: dmd -c -m32 betterc.d -betterC Link with: gcc -m32 betterc.o -Wl,--build-id=none -nostdlib -o "betterc.bin" Linker output: betterc.o: In function `main': betterc.d:(.text.main[main]+0xa): undefined reference to `_d_newitemT' betterc.o:(.data._D22TypeInfo_S7betterc3foo6__initZ+0x0): undefined reference to `_D15TypeInfo_Struct6__vtblZ' collect2: error: ld returned 1 exit status Is there a mistake in my code, or is the documentation lacking?new uses GC. It has nothing to do with structs.
Dec 23 2017
On Sunday, 24 December 2017 at 01:21:53 UTC, rikki cattermole wrote:On 24/12/2017 1:20 AM, Stijn wrote:background, so I hadn't thought of doing that. Thanks![...]new uses GC. It has nothing to do with structs.
Dec 23 2017
On 24/12/2017 1:25 AM, Stijn wrote:On Sunday, 24 December 2017 at 01:21:53 UTC, rikki cattermole wrote:Yeah new = memory allocation. Although maybe you ought to start out with regular D. -betterC is really there for those who want D but can't have druntime. They should already know D pretty well.On 24/12/2017 1:20 AM, Stijn wrote:background, so I hadn't thought of doing that. Thanks![...]new uses GC. It has nothing to do with structs.
Dec 23 2017
On Sunday, 24 December 2017 at 01:29:56 UTC, rikki cattermole wrote:Although maybe you ought to start out with regular D. -betterC is really there for those who want D but can't have druntime. They should already know D pretty well.I'm using -betterC on purpose, doing bare-metal development. Had to learn a new language anyway, and I had been following D for 8 years or so. I started out with a stubbed object.d but that turned out to be too hard, so switched to -betterC by recommendation of some people on IRC.
Dec 23 2017