digitalmars.D.learn - gdc 12.1: undefined references when linking separately compiled files
- kdevel (35/35) May 28 2022 I am trying to build a project with GDC. It successfully compiles
- Tejas (4/8) May 28 2022 Is seperate compilation working successfully for dmd and ldc?
- Adam D Ruppe (3/5) May 28 2022 You might need to add -lgphobos or -lgphobos2 or whatever it is
- kdevel (7/12) May 28 2022 gdc -v -o ppinsta ppinsta.o parser.o
- kdevel (48/49) May 28 2022 ppinsta.d
- Adam D Ruppe (12/13) May 28 2022 Compiling together is faster anyway this is prolly what you want
- kdevel (7/17) May 28 2022 $ gdc -fall-instantiations -c ppinsta.d
- Steven Schveighoffer (7/16) May 28 2022 It should only think that if it sees it instantiated.
- kdevel (4/6) May 28 2022 On Saturday, 28 May 2022 at 15:10:25 UTC, Steven Schveighoffer
- Johan (7/13) May 30 2022 Please check the dlang versions of all compilers. The template
- Alexibu (14/27) Jul 06 2023 I just encountered this problem in recently released debian
- mw (3/16) Jul 06 2023 Using GDC may require rewrite?
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
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
On Saturday, 28 May 2022 at 13:55:09 UTC, Tejas wrote:On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote:dmd: ``` $ dmd -c ppinsta.d $ dmd -c parser.d $ dmd -of=ppinsta ppinsta.o parser.o $ ./ppinsta [] ``` (checking ldc/ldmd2 later)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
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
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.oYou might need to add -lgphobos or -lgphobos2 or whatever it is called too explicitly.
May 28 2022
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 -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 [...] ^^^^^^^^^gdc -o ppinsta ppinsta.o esah.o evaluate.o jsr.o jsw.o parser.o ptvr.o stack.o testdatagenerator.oYou might need to add -lgphobos or -lgphobos2 or whatever it is called too explicitly.
May 28 2022
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
On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote:$ gdc -o ppinsta ppinsta.d parser.dCompiling 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
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 -fall-instantiations -c ppinsta.d $ gdc -c parser.d $ gdc -o ppinsta ppinsta.o parser.o $ ./ppinsta [] Works. THX!$ gdc -o ppinsta ppinsta.d parser.dCompiling 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
May 28 2022
On 5/28/22 10:44 AM, Adam D Ruppe wrote:On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote: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$ gdc -o ppinsta ppinsta.d parser.dCompiling 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.
May 28 2022
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
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: [...]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). -JohanIs this specific to gdc, or does it happen for other compilers as well?The former.
May 30 2022
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: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$ gdc -o ppinsta ppinsta.d parser.dCompiling 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.
Jul 06 2023
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_eUsing GDC may require rewrite? I have thought GDC use the same front-end as DMD & LDC?
Jul 06 2023