[Issue 19291] New: undefined reference linker error with separate compillation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 7 20:30:35 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19291

          Issue ID: 19291
           Summary: undefined reference linker error with separate
                    compillation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: zorael at gmail.com

Manjaro/Arch x86_64, dmd v2.082.0, dub v1.11.0.

The code in the linkererror branch at
https://github.com/zorael/kameloso/tree/linkererror compiles in normal mode but
gives an undefined reference error when building with dub
--build-mode=singleFile.

The error disappears and compilation succeeds if a local import inside a
function (main) is moved up to module-level.

> $ git clone https://github.com/zorael/kameloso -b linkererror
> $ cd kameloso
> $ dub build --build-mode=singleFile
> /usr/bin/ld: .dub/build/application-debug-linux.posix-x86_64-dmd_2082-6DCE8163999240FCF02537A83F2B5667/main_4e3dbc0b.o: in function `_Dmain':
> /home/zorael/src/kameloso/source/kameloso/main.d:10: undefined reference to `_D8kameloso6logger14KamelosoLogger__T8tintImplVE3std12experimentalQCd4core8LogLeveli64ZQByMxFNbNdNiZAya'

--- main.d

import std.experimental.logger;

Logger logger;

void main()
{
    import kameloso.logger;  // <--
    string infotint = (cast(KamelosoLogger)logger).infotint;
}


--- logger.d

module kameloso.logger;

import std.experimental.logger;

class KamelosoLogger : Logger
{
    this(LogLevel lv)
    {
        super(lv);
    }

    private string tintImpl(LogLevel level)() const @property
    {
        return string.init;
    }

    alias infotint = tintImpl!(LogLevel.info);
}

--


More information about the Digitalmars-d-bugs mailing list