I'm getting an unhelpful linker error, what've I got wrong?

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 28 04:40:12 PDT 2015


On Wednesday, 28 October 2015 at 11:11:01 UTC, pineapple wrote:
> When I attempt to compile my code I get the same linker error 
> with both dmd and ldc2. I know where the problematic code is, 
> as I don't get the error when I comment out lines 102 through 
> 107, but I don't understand why it's bad. I must have some 
> misconceptions about how templates work? Is there any way to 
> get more descriptive errors out of the compiler if this sort of 
> thing happens again in the future?
>
> Here's the code:
>
>     http://pastebin.com/kGUPVa59
>
> Here's the problematic lines:
>
>     final streamint writestring(in char[] str){
>         return this.writebuffer!char(str.ptr, str.length);
>     }
>     final streamint writestring(in string str){
>         return this.writebuffer!char(str.ptr, str.length);
>     }
>
> And the linker error:
>
>     Undefined symbols for architecture x86_64:
>       
> "_D6stream6Stream19__T11writebufferTaZ11writebufferMFxPaxlZl", 
> referenced from:
>           _D6stream6Stream11writestringMFxAaZl in stream.o
>           _D6stream6Stream11writestringMFxAyaZl in stream.o
>     ld: symbol(s) not found for architecture x86_64
>     clang: error: linker command failed with exit code 1 (use 
> -v to see invocation)
>     --- errorlevel 1

The "writebuffer" is defined to take an array as parameter. Yet, 
you are passing a pointer and a length to it. Instead, pass the 
parameter "str" to it directly. Also, you do not have to put 
"!char" to there. Compiler will solve it out by itself.


More information about the Digitalmars-d-learn mailing list