www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - strange link error: _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm

reply mw <m g.c> writes:
Hi,

I just encountered a strange link error: I have a `struct` type 
`My_struct`, the program compiles fine, but at link time, it 
errors out:

undefined reference to _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm
undefined reference to _My_struct__xopEqualsMxFKxSQBlQBoQBiZb

looks like it treats My_struct type as `class` type?

I'm just wondering how to fix this?


both compilers report the same link error:

DMD64 D Compiler v2.105.0
LDC - the LLVM D compiler (1.35.0):


Thanks.
Oct 16 2023
next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 16 October 2023 at 18:20:27 UTC, mw wrote:
 Hi,

 I just encountered a strange link error: I have a `struct` type 
 `My_struct`, the program compiles fine, but at link time, it 
 errors out:

 undefined reference to _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm
 undefined reference to _My_struct__xopEqualsMxFKxSQBlQBoQBiZb

 looks like it treats My_struct type as `class` type?

 I'm just wondering how to fix this?


 both compilers report the same link error:

 DMD64 D Compiler v2.105.0
 LDC - the LLVM D compiler (1.35.0):


 Thanks.
Show your code here on in Discord https://discord.gg/wKTvGNpc
Oct 16 2023
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Monday, 16 October 2023 at 19:36:07 UTC, Imperatorn wrote:
 On Monday, 16 October 2023 at 18:20:27 UTC, mw wrote:
 Hi,

 I just encountered a strange link error: I have a `struct` 
 type `My_struct`, the program compiles fine, but at link time, 
 it errors out:

 undefined reference to _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm
 undefined reference to _My_struct__xopEqualsMxFKxSQBlQBoQBiZb

 looks like it treats My_struct type as `class` type?

 I'm just wondering how to fix this?


 both compilers report the same link error:

 DMD64 D Compiler v2.105.0
 LDC - the LLVM D compiler (1.35.0):


 Thanks.
Show your code here on in Discord https://discord.gg/wKTvGNpc
No, show your code here on the forum, don't need to siphon out people to Discord With the forums the problem + solution will be saved for other people
Oct 16 2023
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 16 October 2023 at 20:06:02 UTC, ryuukk_ wrote:
 On Monday, 16 October 2023 at 19:36:07 UTC, Imperatorn wrote:
 On Monday, 16 October 2023 at 18:20:27 UTC, mw wrote:
 [...]
Show your code here on in Discord https://discord.gg/wKTvGNpc
No, show your code here on the forum, don't need to siphon out people to Discord With the forums the problem + solution will be saved for other people
I made a typo, it should say "or", not "on"
Oct 16 2023
parent reply mw <m g.c> writes:
It's very hard to isolate the problem. I have comment out that 
piece part of code for now (non-essential part of my program): 
comment out where the struct is used, not the struct definition.

Anyway, I will try some time later.
Oct 16 2023
parent mw <m g.c> writes:
On Monday, 16 October 2023 at 21:20:39 UTC, mw wrote:
 It's very hard to isolate the problem. I have comment out that 
 piece part of code for now (non-essential part of my program): 
 comment out where the struct is used, not the struct definition.

 Anyway, I will try some time later.
BTW, the struct is generated by https://github.com/dcarp/protobuf-d/blob/master/examples/dub.json using the `--d_opt=message-as-struct` option, it looks like this: ``` struct Foo { Proto(1) string a = protoDefaultValue!string; Proto(2) int b = protoDefaultValue!int; Proto(3) int c = protoDefaultValue!int; } ```
Oct 16 2023
prev sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
xtoHash and xopEquals are generated by the compiler automatically.

Curiously those two symbol names are not demangling.

Given this, I suspect the best thing to do is file a bug report with ldc 
with the code that generated the linker error.
Oct 16 2023
next sibling parent reply mw <mw g.c> writes:
On Tuesday, 17 October 2023 at 00:44:17 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 xtoHash and xopEquals are generated by the compiler 
 automatically.

 Curiously those two symbol names are not demangling.

 Given this, I suspect the best thing to do is file a bug report 
 with ldc with the code that generated the linker error.
Oh the <_My_struct> part is my simplification, it is mangled as something like : _D6..<_My_struct>..__xtoHashFNbNeKxSQBlQBoQBiZm
Oct 16 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 17/10/2023 1:58 PM, mw wrote:
 Oh the <_My_struct> part is my simplification, it is mangled as 
 something like : _D6..<_My_struct>..__xtoHashFNbNeKxSQBlQBoQBiZm
When dealing with linker errors, please do not simplify, it can make problems unsolvable.
Oct 16 2023
parent reply mw <mw g.c> writes:
On Tuesday, 17 October 2023 at 01:14:04 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 On 17/10/2023 1:58 PM, mw wrote:
 Oh the <_My_struct> part is my simplification, it is mangled 
 as something like : 
 _D6..<_My_struct>..__xtoHashFNbNeKxSQBlQBoQBiZm
When dealing with linker errors, please do not simplify, it can make problems unsolvable.
It's just my own module and type name, nothing special or interesting.
Oct 16 2023
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 17/10/2023 2:17 PM, mw wrote:
 It's just my own module and type name, nothing special or interesting.
Doesn't matter. Because I now can't demangle it and figure out what its trying to find without doing that by hand. Every character in a symbol name is significant, you can't remove some of it without changing the meaning of something else. Regardless its probably not something like template elision from what you have said so it might be a compiler bug and I won't be much help there. Of course I can't know for certain without the full symbol hierarchy or the symbol name.
Oct 16 2023
prev sibling parent reply mw <mw g.c> writes:
On Tuesday, 17 October 2023 at 00:44:17 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 xtoHash and xopEquals are generated by the compiler 
 automatically.
These two are for `class`, but shouldn't be generated for `struct`, right?
Oct 16 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
They are for structs as well.
Oct 16 2023
parent reply mw <mw g.c> writes:
On Tuesday, 17 October 2023 at 01:11:13 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 They are for structs as well.
Ah?! I use quite a few struts, but I never have provided such two methods.
Oct 16 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 17/10/2023 2:15 PM, mw wrote:
 On Tuesday, 17 October 2023 at 01:11:13 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 They are for structs as well.
Ah?! I use quite a few struts, but I never have provided such two methods.
Indeed, they are generated by the compiler, not user provided. They are needed when you have fields that are not basic types like other structs.
Oct 16 2023
parent reply mw <m g.c> writes:
On Tuesday, 17 October 2023 at 01:54:12 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 On 17/10/2023 2:15 PM, mw wrote:
 On Tuesday, 17 October 2023 at 01:11:13 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
 They are for structs as well.
Ah?! I use quite a few struts, but I never have provided such two methods.
Indeed, they are generated by the compiler, not user provided. They are needed when you have fields that are not basic types like other structs.
Is string basic types? as I showed one earlier Foo {one string and two ints}, my other struct only has double and long, it also has the same link errors about toHash and opEquals.
Oct 16 2023
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 17/10/2023 4:18 PM, mw wrote:
 Is string basic types? as I showed one earlier Foo {one string and two 
 ints}, my other struct only has double and long, it also has the same 
 link errors about toHash and opEquals.
string is not a basic type, its a slice, which means pointer.
Oct 16 2023