www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - AA rehash link error

reply =?UTF-8?B?IsOYaXZpbmQi?= <oivind.loe gmail.com> writes:
When building my program by compiling .o files first and then 
linking, everything links fine, but when I try to compile all the 
source files at once, I get the following link error:

build/debug/dboss-debug.o: In function ` property 
/usr/include/dmd/druntime/import/object.di:465: undefined 
reference to 

The AA in question is a static class member declared as follows:

   static immutable Cmd[string] m_cmds;

And Cmd is a class defined in the same class:

   static class Cmd {
     alias string function(ProcCmd c, string[] args) fExec;

     string  m_cmd;   //Invocation name
     string  m_desc;  //Description of command
     fExec   m_exec;  //Function implementing command

     this(string cmd, string desc, fExec exec) {
       m_cmd = cmd;
       m_desc = desc;
       m_exec = exec;

What am I doing wrong? This is working perfectly fine when 
building object files before linking.
Aug 13 2012
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
You're not doing anything wrong, this is an old bug that shows up 
at random.

I worked around it in my cgi.d by writing a function like this:

// Referencing this gigantic typeid seems to remind the compiler
// to actually put the symbol in the object file. I guess the 
// assoc array array isn't actually included in druntime
void hackAroundLinkerError() {
       // this is getting kinda ridiculous btw. Moving assoc arrays
       // to the library is the pain that keeps on coming.

       // eh this broke the build on the work server
       // writeln(typeid(immutable(char)[][immutable(string[])]));

I never call that function, its simple presence is all that's 

You should be able to do the same. Try dropping this at the 
bottom of your file with the definition:

void hackAroundLinkerError() {
     writeln(typeid(immutable Cmd[string]));

Or some similar variant and see if it works.
Aug 16 2012