Rainer Deyke wrote:
On 11/14/2010 00:09, Walter Bright wrote:
I suspect that trying to guess what modules should be added to the
linker list may cause far more confusion than enlightenment when it goes
awry. Currently, a lot of people seem to regard what a linker does as
magic. Making it more magical won't help.

It seems completely straightforward to me.  If module A imports module
B, then module A depends on module B, therefore compiling and linking
module A should also cause module B to be compiled and linked.  Apply
recursively.  The only part of this that is remotely difficult - mapping
module names to files on the disk - is already done by the compiler.

This would only happen when compiling and linking as a single step,
which would be the preferred way to invoke DMD.  When linking as a
separate step, all object files would still need to be individually
passed to the linker.

The compiler can't tell:

1. if the implementation of a particular import is in a library or an object 
file.

2. if the object file is not in the same place as the import file

So you might say "let's use some reasonable defaults for these."

Ok, but when that goes awry (and it absolutely will), there will be left behind some very confused people. Consider that I regularly get requests for help from people who are linking with the wrong version of phobos.lib which they insist does not exist on their computer. Eventually, it turns out that it did exist and was on the library search path. This problem would get much, much worse.

Object file names do not always match the import names, and there are various other scenarios that are not so straightforward. If the compiler goes down the road of defaults, and the user thinks that a.obj is being linked in while actually some random b.obj is, and mysterious failures happen, he's going to be very unhappy. I'd certainly rather have an undefined symbol message when I make a mistake putting together the makefile than something wrong and hidden from me happening.

Is this real? Yes. I also regularly get requests for help from people who do not understand how objects are pulled from a library by the linker, and not just from vm people. They are not going to be helped by the compiler mysteriously linking in whatever it finds first. If they are baffled by an "undefined symbol" message, they are really going to get gobsmacked by this.

To really manage this sort of thing in a way that works, you need to use an IDE that has a notion of a "project" and what files are in that project and where all the object files and libraries are.

Reply via email to