www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21299] New: [LINK] undefined reference to


          Issue ID: 21299
           Summary: [LINK] undefined reference to
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

Reduced from link error found in regression from Issue 21294 (which caused a
refactoring change in dmd to be reverted).

It may not be *the* cause of the Issue 21294, but it's certainly a major issue
that needs to be addressed, as this is preventing code in the dmd front-end
from being moved around.

Test script:
dmd -c dmd/mtype.d 
dmd -c dmd/func.d 
dmd -c dmd/root/stringtable.d 
dmd -main mtype.o func.o stringtable.o

Test sources
// dmd/func.d
module dmd.func;
import dmd.mtype;
import dmd.root.stringtable;
class FuncDeclaration {
    StringTable!Type stringtable;

// dmd/mtype.d
module dmd.mtype;
import dmd.func;
import dmd.root.stringtable;
class Type {
    StringTable!Type stringtable;

// dmd/root/stringtable.d
module dmd.root.stringtable;
struct StringValue(T)
    char* lstring()
        return cast(char*)&this;

struct StringTable(T)
    StringValue!T* insert()
        return getValue;

    uint allocValue()
        StringValue!(T) sv;
        sv.lstring[0] = 0;
        return 0;

    StringValue!T* getValue()
        return cast(StringValue!T*)&this;

Results in the link error:
/usr/bin/ld: mtype.o: in function
undefined reference to
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Oct 08 2020