Search code examples
linkerd

Linker Error; Cannot Link: _D16TypeInfo_HAyayAa6__initZ


When linking my code, I get the following error:

../Build/main.o:(.data._D16TypeInfo_yHAyaAa6__initZ+0x10): undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

I have no idea where the error is occurring, so there is not much code wise I can offer you. There is a lot of code.


Solution

  • Try adding this code to your file with main():

    void aaHack() {
        import std.stdio;
        writeln(typeid(immutable(char[])[string]));
    }
    

    and recompile, see if it works. I'm sure your error is caused by an old bug in associative arrays that is incredibly hard to reproduce; it seems to come and go at random, making it hard to fix too. The exact type needed is something I'm not sure about, I'm guessing there based on an eyeball demangle, but I think this is it.

    Anyway, the associative array implementation in D right now is stuck in a halfway point between two ideas: implemented in the language via special runtime calls, and implemented in the library with no compiler support except syntax sugar. Again, I'm not sure this is the cause, but it came in around these changes were made, so I think that's it. What I believe is happening is you reference the AA type, which then gets used via the half-done library type, but then the functions need the typeinfo for the compiler's magic calls, and it never gets correctly inserted. Or something.

    But the hack workaround is to forcibly mention the typeid manually somewhere to bridge the gap. My cgi.d has a block of 14 lines of working around this thing over and over again: fully immutable keys and/or values seem to be the edge case that breaks it, whereas tail-immutable arrays (e.g. strings) work fine. Maybe the compiler assumes the other thing will be stripped off and isn't, idk, but the hack has worked reasonably well for me.