Thread overview
[Issue 19945] In betterC strange linker error can occur when importing alias of template struct
Jun 07, 2019
Nathan S.
Jun 04, 2022
Walter Bright
Jun 04, 2022
Richard Cattermole
June 07, 2019
https://issues.dlang.org/show_bug.cgi?id=19945

Nathan S. <n8sh.secondary@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |betterC

--
June 04, 2022
https://issues.dlang.org/show_bug.cgi?id=19945

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|---                         |INVALID

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
The -betterC is for programs that do not use the D runtime library. At link time, the D runtime library is not searched by the linker, only the C runtime library is.

Your example program is using std.random, which is part of the D runtime library. The undefined symbol:

_D3std6random__T24LinearCongruentialEngineTkVki48271Vki0Vki2147483647ZQCc5frontMxFNaNbNdNiNfZk

looks like std.random.LinearCongruentialEngine.front() is not found, which makes sense because that function is in the D runtime library which is not linked in.

_D3std6random__T24LinearCongruentialEngineTkVki48271Vki0Vki2147483647ZQCc6__initZ

is the static initializer for std.random.LinearCongruentialEngine and is also not found because it is in the D runtime library.

If the compile is able to inline everything it needs from the D runtime library, it will work because it then won't need to look in the D runtime library to find it. You'll know when it doesn't work by the appearance of the undefined symbols.

I'm going to mark this as invalid because using the D runtime library in -betterC is not officially supported (even though it may work) since the whole point of -betterC is to not use the D runtime library.

--
June 04, 2022
https://issues.dlang.org/show_bug.cgi?id=19945

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alphaglosined@gmail.com

--- Comment #2 from Richard Cattermole <alphaglosined@gmail.com> ---
Walter is probably correct that we cannot fix this.

However, it should work due to LinearCongruentialEngine being templated.

For dmd if -allinst makes this code work, then it is indeed a template emission bug.

--