Search code examples
ddub

D - module main is in file "main.d" which cannot be read when compiling using DUB


I have following for dub.json:

{
    "name": "foo",
    "targetType": "executable",
    "sourceFiles": ["main.d"],
    "mainSourceFile": "main.d",
    "importPaths": ["src"],
    "sourcePaths": ["src"],
}

I have my main.d (with basic hello-world-like program) in src folder. If I run dub build I get the error mentioned in the question title. If I move main.d from src to the same directory where dub.json resides, the error goes away. I'd very much like to keep the sources in src, but that doesn't compile. How do I fix it?

I'm aware of there two questions: first, second, but the situation is different from both of them. In the first one, the module that's not found is a dependency, which is not the case here. In the second, the compilation is performed manually and not via DUB (I've tried passing -Isrc to the compiler as answers to that question suggested, though, but it didn't help).

I'm using DUB v1.3.0 on Arch Linux (64 bit) and LDC v1.2.0 (but the same happens if I use DMD v2.074.0)


Solution

  • Seems to work if you use just:

    {
        "name": "foo",
        "targetType": "executable",
        "sourcePaths": ["src"]
    }