ModuleInfo Error
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Wed Aug 9 15:00:56 PDT 2017
On Wednesday, 9 August 2017 at 21:29:07 UTC, Johnson Jones wrote:
> I routinely get this error when I forget to add a module that I
> import to the project.
You learn it pretty quickly though, don't you?
> I guess this is due to the fact that the module does not have a
> library backing and the __ModuleInfo function isn't generated
> for it so it doesn't exist anywhere? (Just guessing)
Yeah, basically. __ModuleInfo isn't a function, rather it is a
block of static data telling the runtime where its static ctors,
dtors, unittests, etc. are, but same idea.
When you compile a .d file, the module info is automatically
generated and put in the file with the functions you write.
When you import a module, the compiler emits a reference to that
moduleinfo so it can run its static ctors, etc., if present in
your program.
Importing a module without linking in its library or object file
causes the error you see.
> Surely we could get a better error message for this or dmd
> could somehow try and automatically remedy the situation?
So it technically isn't actually dmd generating that error... it
happens at the link step, after dmd is done. Though dmd could
parse the linker output and replace it with different text... but
that is a pretty big pain and like I hinted above, this is the
kind of thing you might be slightly baffled by the first time,
but quickly learn what it means so the ongoing cost is pretty
small.
Replacing the text from the linker isn't just a one time
implementation either: it'd have to keep up with changes from
other linkers or version updates, and would likely break any
special output (such as colors) that it tries to do.
However...
> If so, why not keep track of all the modules that have bee used
> and if this error occurs, compile the module or do whatever
> needs to be done so the error is not necessary?
...that's what rdmd does. I think it is distributed with the
compiler.
dmd itself doesn't do that though since a valid use case (and
fairly common with dmd's corporate users) is to compile and link
separately, like people do with C++, to improve working with
their complex build systems (speed, external assets, proprietary
libraries, etc. don't work as well with my preferred "dmd *.d"
strategy so they make it fancy af), so automatically compiling
everything would actually be a step backward for those people.
But you might want to try using rdmd. You just pass it the
function with main and it figures out the rest by walking the
import path, then calls dmd to actually compile.
> New users to D will be thrown by this error. It is meaningless
> as far as being helpful and there is virtually no online help
> for it...
It is a FAQ... though cannot easily be found. Maybe you (or
someone else) should ask on SO and put an answer up there so we
can start linking to that?
More information about the Digitalmars-d
mailing list