www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - gdc 12.1: undefined references when linking separately compiled files

reply kdevel <kdevel vogtner.de> writes:
I am trying to build a project with GDC. It successfully compiles 
with dmd and ldmd2. When I use gdc in one go the binary is 
successfully build:

```
$ gdc -o ppinsta esah.d evaluate.d jsr.d jsw.d parser.d ppinsta.d 
ptvr.d stack.d testdatagenerator.d
```

Though after compiling separately the linking fails:

```
$ make -f Makefile.gdc -j3
gdc -o ppinsta.o -c ppinsta.d
gdc -o esah.o -c esah.d
gdc -o evaluate.o -c evaluate.d
gdc -o jsr.o -c jsr.d
gdc -o jsw.o -c jsw.d
gdc -o parser.o -c parser.d
gdc -o ptvr.o -c ptvr.d
gdc -o stack.o -c stack.d
gdc -o testdatagenerator.o -c testdatagenerator.d
gdc -o ppinsta ppinsta.o esah.o evaluate.o jsr.o jsw.o parser.o 
ptvr.o stack.o testdatagenerator.o
ppinsta.o: In function 
`_D3std6format8internal5write__T8getWidthTAyaZQoFNaNfQlZl':
ppinsta.d:(.text+0x1c5a): undefined reference to 
`_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAyaZQoFQhZ9__lambda2Z__TQCpTQBcZQCxMFNaNfQBpZb'
ppinsta.o: In function 
`_D3std6format8internal5write__T20formatValueImplUlongTSQCb5array__T8AppenderTAyaZQoTaZQCdFNaNfKQBpmIbMKxSQDzQDy4spec__T10FormatSpecTaZQpZv':
ppinsta.d:(.text+0x2bcc): undefined reference to 
`_D3std9algorithm9searching__T3allSQBg6format8internal5write__T20formatValueImplUlongTSQDg5array__T8AppenderTAyaZQoTaZQCdFKQBlmIbMKxSQFaQDu4spec__T10FormatSpecTaZQpZ10__lambda16Z__TQFvTAaZQGcMFNaNfQmZb'
ppinsta.d:(.text+0x2c5b): undefined reference to 
`_D3std9algorithm9searching__T3allSQBg6format8internal5write__T20formatValueImplUlongTSQDg5array__T8AppenderTAyaZQoTaZQCdFKQBlmIbMKxSQFaQDu4spec__T10FormatSpecTaZQpZ10__lambda17Z__TQFvTAaZQGcMFNaNfQmZb'
collect2: error: ld returned 1 exit status
make: *** [ppinsta] Error 1
```

Any ideas?
May 28 2022
next sibling parent reply Tejas <notrealemail gmail.com> writes:
On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote:
 I am trying to build a project with GDC. It successfully 
 compiles with dmd and ldmd2. When I use gdc in one go the 
 binary is successfully build:

 [...]
Is seperate compilation working successfully for dmd and ldc? The only bug I know of regarding seperate compilation is https://issues.dlang.org/show_bug.cgi?id=20641
May 28 2022
parent reply kdevel <kdevel vogtner.de> writes:
On Saturday, 28 May 2022 at 13:55:09 UTC, Tejas wrote:
 On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote:
 I am trying to build a project with GDC. It successfully 
 compiles with dmd and ldmd2. When I use gdc in one go the 
 binary is successfully build:

 [...]
Is seperate compilation working successfully for dmd and ldc?
dmd: ``` $ dmd -c ppinsta.d $ dmd -c parser.d $ dmd -of=ppinsta ppinsta.o parser.o $ ./ppinsta [] ``` (checking ldc/ldmd2 later)
 The only bug I know of regarding seperate compilation is 
 https://issues.dlang.org/show_bug.cgi?id=20641
May 28 2022
parent kdevel <kdevel vogtner.de> writes:
On Saturday, 28 May 2022 at 14:37:07 UTC, kdevel wrote:
 dmd:

 ```
 $ dmd -c ppinsta.d
 $ dmd -c parser.d
 $ dmd -of=ppinsta ppinsta.o parser.o
 $ ./ppinsta
 []
 ```
 (checking ldc/ldmd2 later)
``` $ ldc2 -c ppinsta.d && ldc2 -c parser.d && ldc2 -of=ppinsta ppinsta.o parser.o && ./ppinsta [] $ ldmd2 -c ppinsta.d && ldmd2 -c parser.d && ldmd2 -of=ppinsta ppinsta.o parser.o && ./ppinsta [] ``` Both okay.
May 28 2022
prev sibling next sibling parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote:
 gdc -o ppinsta ppinsta.o esah.o evaluate.o jsr.o jsw.o parser.o 
 ptvr.o stack.o testdatagenerator.o
You might need to add -lgphobos or -lgphobos2 or whatever it is called too explicitly.
May 28 2022
parent kdevel <kdevel vogtner.de> writes:
On Saturday, 28 May 2022 at 14:03:13 UTC, Adam D Ruppe wrote:
 On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote:
 gdc -o ppinsta ppinsta.o esah.o evaluate.o jsr.o jsw.o 
 parser.o ptvr.o stack.o testdatagenerator.o
You might need to add -lgphobos or -lgphobos2 or whatever it is called too explicitly.
gdc -v -o ppinsta ppinsta.o parser.o It says [...]gcc-12.1/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.1.0/collect2 \ [...]ppinsta.o parser.o -Bstatic -lgphobos [...] ^^^^^^^^^
May 28 2022
prev sibling parent reply kdevel <kdevel vogtner.de> writes:
On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote:
 Any ideas?
ppinsta.d ``` import std.stdio : write, writeln; import parser; // <- comment this out and gdc links void main () { string [string] h; writeln (h); } ``` parser.d ``` module parser; import std.regex : regex; private immutable auto VariableName = regex("^[a-zA-Z]*$"); ``` Compile in one go: ``` $ gdc -o ppinsta ppinsta.d parser.d $ ./ppinsta [] ``` Compiled separately: ``` $ gdc -c ppinsta.d $ gdc -c parser.d $ gdc -o ppinsta ppinsta.o parser.o ppinsta.o: In function `_D3std6format8internal5write__T8getWidthTAyaZQoFNaNfQlZl': ppinsta.d:(.text+0x11ea): undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAyaZQoFQhZ9__lambda2Z__TQCpTQBcZQCxMFNaNfQBpZb' ppinsta.o: In function `_D3std6format8internal5write__T8getWidthTAaZQnFNaNfQkZl': ppinsta.d:(.text+0x16ba): undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAaZQnFQgZ9__lambda2Z__TQCoTQBbZQCwMFNaNfQBoZb' ppinsta.o: In function `_D3std6format8internal5write__T20formatValueImplUlongTSQCb5array__T8AppenderTAyaZQoTaZQCdFNaNfKQBpmIbMKxSQDzQDy4spec__T10FormatSpecTaZQpZv': ppinsta.d:(.text+0x21d9): undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T20formatValueImplUlongTSQDg5array__T8AppenderTAyaZQoTaZQCdFKQBlmIbMKxSQFaQDu4spec__T10FormatSpecTaZQpZ10__lambda16Z__TQFvTAaZQGcMFNaNfQmZb' ppinsta.d:(.text+0x2268): undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T20formatValueImplUlongTSQDg5array__T8AppenderTAyaZQoTaZQCdFKQBlmIbMKxSQFaQDu4spec__T10FormatSpecTaZQpZ10__lambda17Z__TQFvTAaZQGcMFNaNfQmZb' ppinsta.o: In function `_D3std6format8internal5write__T8getWidthTAwZQnFNaNbNiNfQoZl': ppinsta.d:(.text+0x2996): undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAwZQnFQgZ9__lambda2Z__TQCoTQBbZQCwMFNaNbNiNfQBsZb' collect2: error: ld returned 1 exit status ```
May 28 2022
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote:
 $ gdc -o ppinsta ppinsta.d parser.d
Compiling together is faster anyway this is prolly what you want most the time. But I know what's going on now, it is the template emission thing, the compiler thinks, since it is from std, it was already compiled somewhere else and skips it but it isn't actually there so the linker errors. Using gdc -fall-instantiations -c parser.d Might generate it in that parser.o getting it to link. Might need to be used in all builds but I *think* just here, hard to say without a test.
May 28 2022
next sibling parent kdevel <kdevel vogtner.de> writes:
On Saturday, 28 May 2022 at 14:44:56 UTC, Adam D Ruppe wrote:
 On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote:
 $ gdc -o ppinsta ppinsta.d parser.d
Compiling together is faster anyway this is prolly what you want most the time. But I know what's going on now, it is the template emission thing, the compiler thinks, since it is from std, it was already compiled somewhere else and skips it but it isn't actually there so the linker errors. Using gdc -fall-instantiations -c parser.d
$ gdc -fall-instantiations -c ppinsta.d $ gdc -c parser.d $ gdc -o ppinsta ppinsta.o parser.o $ ./ppinsta [] Works. THX!
May 28 2022
prev sibling next sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 5/28/22 10:44 AM, Adam D Ruppe wrote:
 On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote:
 $ gdc -o ppinsta ppinsta.d parser.d
Compiling together is faster anyway this is prolly what you want most the time. But I know what's going on now, it is the template emission thing, the compiler thinks, since it is from std, it was already compiled somewhere else and skips it but it isn't actually there so the linker errors.
It should only think that if it sees it instantiated. If it's instatiated in std, it should be included in the built phobos library. If it's not instantiated in std, then the compiler should be putting it inside the object file. Is this specific to gdc, or does it happen for other compilers as well? -Steve
May 28 2022
parent reply kdevel <kdevel vogtner.de> writes:
On Saturday, 28 May 2022 at 15:10:25 UTC, Steven Schveighoffer 
wrote:
[...]
 Is this specific to gdc, or does it happen for other compilers 
 as well?
The former.
May 28 2022
parent Johan <j j.nl> writes:
On Saturday, 28 May 2022 at 22:23:34 UTC, kdevel wrote:
 On Saturday, 28 May 2022 at 15:10:25 UTC, Steven Schveighoffer 
 wrote:
 [...]
 Is this specific to gdc, or does it happen for other compilers 
 as well?
The former.
Please check the dlang versions of all compilers. The template emission scheme is changing quite often between versions, indeed leading to linking problems with separate compilation and complex template instantiation trees (one of the main compiler upgrade issues at Weka, with LDC). -Johan
May 30 2022
prev sibling parent reply Alexibu <alex sunopti.com> writes:
On Saturday, 28 May 2022 at 14:44:56 UTC, Adam D Ruppe wrote:
 On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote:
 $ gdc -o ppinsta ppinsta.d parser.d
Compiling together is faster anyway this is prolly what you want most the time. But I know what's going on now, it is the template emission thing, the compiler thinks, since it is from std, it was already compiled somewhere else and skips it but it isn't actually there so the linker errors. Using gdc -fall-instantiations -c parser.d Might generate it in that parser.o getting it to link. Might need to be used in all builds but I *think* just here, hard to say without a test.
I just encountered this problem in recently released debian bookworm (gdc 12.2.0), I was able to fix these undefined lambdas inside std library with -fall-instantiations, and a bunch of other undefined lambdas in my own code by changing template arguments of the form alias e = (a => a) to a separate definition auto (T)default_e(T a) { return a; } and alias e = default_e
Jul 06 2023
parent mw <mw g.c> writes:
On Thursday, 6 July 2023 at 22:44:27 UTC, Alexibu wrote:

 I just encountered this problem in recently released debian 
 bookworm (gdc 12.2.0), I was able to fix these undefined 
 lambdas inside std library with -fall-instantiations, and a 
 bunch of other undefined lambdas in my own code by changing 
 template arguments of the form
 alias e = (a => a)
 to a separate definition
 auto (T)default_e(T a)
 {
    return a;
 }
 and
 alias e = default_e
Using GDC may require rewrite? I have thought GDC use the same front-end as DMD & LDC?
Jul 06 2023