can't link a code, is it a bug or my fault?
Iliya
iliya.grachev at gmail.com
Thu Mar 11 16:41:55 UTC 2021
Hello.
I am using dmd 2.094.1 on linux for compiling a piece code I
found on the github. Unfortunately linker can't link it as it
can't find opCall symbol instantiation demangled as:
pure nothrow @nogc @safe bool
app.IsEqual!(char).IsEqual.opCall(in char, in char)
Do you have any ideas on:
1. Why compiler searches for such function attributes - pure
nothrow @nogc @safe, as I don't specify them. Is this a bug or
feature?)
2. What changes are needed to compile this rather simple example.
Please, help me!
Reference to my piece of code in app.d:
struct IsEqual(T)
{
static bool opCall( in T p1, in T p2 )
{
return p1 == p2;
}
}
size_t find(T, Pred = IsEqual!(T))
(in T[] haystack, in T needle, Pred pred = Pred.init)
{
foreach ( pos, cur; haystack )
{
if( pred( cur, needle ) )
return pos;
}
return haystack.length;
}
int main(string[] args)
{
auto pos = find("abc" , 'b');
assert(pos == 1);
return 0;
}
Linker error message:
Linking...
/usr/bin/ld:
.dub/build/application-debug-linux.posix-x86_64-dmd_2094-BD99179F1B52B13DDA1C2B0172F5081E/app.bin.o: in function `_D3app__T4findTaTSQq__T7IsEqualTaZQlZQBcFNaNbNiNfIAaIaQBlZm':
source/app.d:15: undefined reference to
`_D3app__T7IsEqualTaZQl6opCallFNaNbNiNfIaIaZb'
collect2: error: ld returned 1 exit status
ddemangle output on these symbols:
_D3app__T7IsEqualTaZQl6opCallFNaNbNiNfIaIaZb
pure nothrow @nogc @safe bool
app.IsEqual!(char).IsEqual.opCall(in char, in char)
_D3app__T4findTaTSQq__T7IsEqualTaZQlZQBcFNaNbNiNfIAaIaQBlZm
pure nothrow @nogc @safe ulong app.find!(char,
app.IsEqual!(char).IsEqual).find(in char[], in char,
app.IsEqual!(char).IsEqual)
Thanks you!
More information about the Digitalmars-d-learn
mailing list