Nested C++ namespace library linking

Guillaume Chatelet via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 20 13:10:58 PST 2015


Consider the following foo.cpp

namespace A {
namespace B {
   struct Type {};
   int foo(Type unused){ return 42; }
}
}

Compile it : g++ foo.cpp -c -o foo.o

Then the following main.d

extern(C++, A.B) {
   struct Type {}
   int foo(Type unused);
}

void main() {
   foo(Type());
}

Compile it : dmd main.d foo.o
It fails with : undefined reference to « A::B::foo(A::Type) »

It looks like the Type is not resolved in the right namespace. 
A::Type instead of A::B::Type. Did I miss something or is this a 
bug ?

I also tried fully qualifying foo and Type but I end up with the 
exact same error :
   A.B.foo(A.B.Type());


More information about the Digitalmars-d-learn mailing list