www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - /usr/bin/ld: [...] undefined reference to

reply Anonymouse <zorael gmail.com> writes:
I'm trying to build my thing with gdc. It (now) compiles, but 
fails to link on this Manjaro/Arch laptop with gdc 12.2.0.

```
/usr/bin/ld: /tmp/ccstWTAS.o: in function 
`_D3std6format8internal5write__T8getWidthTAyaZQoFNaNfQlZl':
/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include/d/std/format/in
ernal/write.d:3819: undefined reference to
`_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAyaZQoFQhZ9__lambda2Z__TQCpTQBcZQCxMFNaNfQBpZb'
/usr/bin/ld: /tmp/ccstWTAS.o: in function 
`_D3std6format8internal5write__T8getWidthTAaZQnFNaNfQkZl':
/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include/d/std/format/in
ernal/write.d:3819: undefined reference to
`_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAaZQnFQgZ9__lambda2Z__TQCoTQBbZQCwMFNaNfQBoZb'
[...]
```

A few lines like those covering half a screen, all of it of 
phobos.

What conventional wisdom I've picked up somewhere along the way 
says to use `-allinst` in cases like these, and after asking 
around on the Discord and finding out about gdc's equivalent 
`-fall-instantiations`, it now links on a different Ubuntu 
machine with gdc 12.1.0. No luck still with the laptop and its 
12.2.0, although the linker outputs fewer errors now.

What does `-allinst` even do and why does it seem to be 
insufficient here?
Dec 20 2022
parent reply Paul Backus <snarwin gmail.com> writes:
On Tuesday, 20 December 2022 at 20:01:04 UTC, Anonymouse wrote:
 What does `-allinst` even do
`-allinst` tells the compiler to generate code for all instantiated templates, even if it thinks that code has already been generated in a different object file. Why would the compiler think that? Sometimes, which templates get instantiated can depend on which flags the code is compiled with. If you compile your code with one set of flags, and link it against a library compiled with a different set of flags, then the different invocations of the compiler may disagree on which templates should end up in which object files.
 and why does it seem to be insufficient here?
Hard to say without more information. Are you compiling with `-preview=dip1000`? If not, does adding that flag fix the error?
Dec 20 2022
parent reply Anonymouse <zorael gmail.com> writes:
On Tuesday, 20 December 2022 at 20:55:08 UTC, Paul Backus wrote:

Apologies for the late reply.

 On Tuesday, 20 December 2022 at 20:01:04 UTC, Anonymouse wrote:
 What does `-allinst` even do
`-allinst` tells the compiler to generate code for all instantiated templates, even if it thinks that code has already been generated in a different object file.
[...] I see. That makes sense. When things fail (requiring `-allinst`), is that a bug I should report or a fact of life to lament?
 and why does it seem to be insufficient here?
Hard to say without more information. Are you compiling with `-preview=dip1000`? If not, does adding that flag fix the error?
I'm not compiling with `dip1000`. Adding it just adds some extra lines to the top of the linker errors. Full demangled non-`dip1000` error, slightly formatted for readability; ``` /usr/bin/ld: ../../.dub/packages/requests-2.0.9/requests/.dub/build/[...]/librequests.a: in function `pure safe void std.format.internal.write.formatValueImpl!(void delegate(scope const(char)[]) pure nothrow safe, ulong, char).formatValueImpl(ref void delegate(scope const(char)[]) pure nothrow safe, const(ulong), scope ref const(std.format.spec.FormatSpec!(char).FormatSpec))': /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include/d/std/format/i ternal/write.d:171: undefined reference to `pure nothrow nogc trusted const(char)[] std.format.internal.write.formatValueImpl!(void delegate(scope const(char)[]) pure nothrow safe, ulong, char).formatValueImpl(ref void delegate(scope const(char)[]) pure nothrow safe, const(ulong), scope ref const(std.format.spec.FormatSpec!(char).FormatSpec)).__lambda5!( long).__lambda5(ref ulong)' /usr/bin/ld: ../../.dub/packages/requests-2.0.9/requests/.dub/build/[...]/librequests.a: in function `pure safe immutable(char)[] std.algorithm.searching.find!(std.algorithm.mutation.stripLeft (immutable(char)[], char).stripLeft(immutable(char)[], char).__lambda3, immutable(char)[]).find(immutable(char)[])': /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include/d/std/algorit m/searching.d:1858: undefined reference to `pure nothrow nogc safe bool std.algorithm.mutation.stripLeft!(immutable(char)[], char).stripLeft(immutable(char)[], char).__lambda3!(dchar).__lambda3(dchar)' collect2: error: ld returned 1 exit status Error gdc failed with exit code 1. ``` In this case it's even in an external dependency (`requests`), which compiles by itself but not when dub builds my thing with it. I'm not sure what to do.
Dec 22 2022
parent Siarhei Siamashka <siarhei.siamashka gmail.com> writes:
On Thursday, 22 December 2022 at 15:32:28 UTC, Anonymouse wrote:
 I'm not sure what to do.
If it links on Ubuntu, but not on Manjaro/Arch, then is it possible that the GDC package from Manjaro/Arch is somehow provided with a missing, misconfigured or broken Phobos library? Maybe try to compile GDC from sources yourself?
Dec 22 2022