www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12721] New: Unresolved Symbols when Linking

https://issues.dlang.org/show_bug.cgi?id=12721

          Issue ID: 12721
           Summary: Unresolved Symbols when Linking
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: puneet coverify.org

Compiles and runs when the modules are compiled and linked in one go:
$ dmd bar.d foo.d;

But if the modules are compiled separately, I get missing symbols:
$ dmd -c bar.d
$ dmd -c foo.d
$ dmd -ofbar bar.o foo.o
bar.o: In function
`_D3foo34__T3FooS19_D3foo4Wrap3fooMFZvViN1Z3Foo31__T4elabTC3foo4WrapTC3foo4WrapZ4elabFNaNbNfC3foo4WrapC3foo4WrapZv':
bar.d:(.text._D3foo34__T3FooS19_D3foo4Wrap3fooMFZvViN1Z3Foo31__T4elabTC3foo4WrapTC3foo4WrapZ4elabFNaNbNfC3foo4WrapC3foo4WrapZv+0xe):
undefined reference to
`_D3foo3Bar42__T4FooTTC3foo4WrapS19_D3foo4Wrap3fooMFZvZ4FooT7__ClassZ'
bar.d:(.text._D3foo34__T3FooS19_D3foo4Wrap3fooMFZvViN1Z3Foo31__T4elabTC3foo4WrapTC3foo4WrapZ4elabFNaNbNfC3foo4WrapC3foo4WrapZv+0x2a):
undefined reference to
`_D3foo3Bar42__T4FooTTC3foo4WrapS19_D3foo4Wrap3fooMFZvZ4FooT6__ctorMFNaNbNiNfC3foo4WrapZC3foo3Bar42__T4FooTTC3foo4WrapS19_D3foo4Wrap3fooMFZvZ4FooT'
collect2: error: ld returned 1 exit status
--- errorlevel 1


// module bar.d
import foo;

class Frop: Wrap{}

void main() {
  Frop frop = new Frop;
  frop.bar();
}

// module foo.d
class Foo(alias F, size_t S=0) {
  static elab(T, L)(T t, L l) {
    t.new t.FooT!(T, F)(t);
  }
}
auto reDelegate(alias F, T)(T e) {
  final getFuncName() {
    return "e." ~ __traits(identifier, F);
  }
  typeof(& mixin(getFuncName)) dg;
  return dg;
}
void bar(T)(T t)
{
  static if(t.tupleof.length) {
    t.tupleof[0].elab(t, t);
  }
  static if(is(T B == super) && is(B[0] : Bar)) {
    B[] b ;
    bar(b);
  }
}
class Bar {
  class FooT(T, alias F): Foo!(F) {
    this(T t) {
      auto dg = reDelegate!F(t);
    }
  }
}
class Wrap: Bar {
  void foo() {}
  Foo!(foo, -1) foo_;
}

--
May 09 2014