ModuleInfo Error

Johnson Jones via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 9 15:43:03 PDT 2017


On Wednesday, 9 August 2017 at 22:00:56 UTC, Adam D. Ruppe wrote:
> 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?
>

no ;/ I have a memory like a rock. Which is either infinite or 
zero ;/ I tend to do a lot of things and after months of not 
seeing something I tend to flush my cache. Specially if I don't 
program in D for a while. It's one thing when you do something 
every day but when you do things in squirts, you tend to memorize 
what you need to know for that purpose then soon forget when you 
no longer need it.


>> 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?

Well, I use Visual D and not sure if it can use rdmd(I'm sure it 
can be hacked) . Is there any benefits or downsides to doing this?

I guess it's not a huge deal at the end of the day... but stuff 
like this just shouldn't be an issue. Are we going to be dealing 
with such things 50 years down the road? (well, not us, but the 
next generation?)  I find most of the problems that we have(not 
just as programmers, but as human beings) tend to be because 
people cannot cut ties with the past and learn from their 
mistakes.  Do we even need to separate the linker and compiler? 
Shouldn't they be able to communicate with each other internally 
to get the most information they can to make our lives easier? A 
simple switch could be used to separate linking and compiling. I 
feel that "modern" programming is still trapped in the past and 
we all ultimately suffer from it. Most people just don't realize 
how much better it could be. How many people have quit using D 
because of all the issues it has or simply because it doesn't 
have the momentum to carry them through life? I've seen a couple 
recently simply cut ties. They wouldn't have to do this if they 
could make a living using D, which means that D is has failed 
them, which is sad  ;/ I don't think the powers at be really 
comprehend those things as they have don't have to worry nor 
experience those things to understand... hence, there is no 
motivation to get D on the right footing so it is not such a 
problem. An unfortunate set of circumstances.

Anyways, I'll just try to remember, ranting about that stuff 
makes it stick in my mind better I guess, and at least a forum 
search of __ModuleInfo should bring up something ;)


More information about the Digitalmars-d mailing list