www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: linker wrapper

reply bearophile <bearophileHUGS lycos.com> writes:
Walter:

 Top 3 linker questions:
 
 1. What does it mean when it says "foo is referenced but not defined" ?
 
 2. What does it mean when it says that "foo is defined in more than one
module" ?
 
 3. Why is my executable file so large?
 
 
 While it's nice to demangle the names, and optlink does so for C++ names, it 
 doesn't reduce the confusion about what the linker is doing. Surprisingly, I
see 
 these questions not just from newbies, but regularly from people with 10+
years 
 of experience.

A new fresh trouble, I think I have already seen about 10-15 persons ask this question in D.learn: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=22772 Bye, bearophile
Nov 13 2010
parent reply Walter Bright <newshound2 digitalmars.com> writes:
bearophile wrote:
 A new fresh trouble, I think I have already seen about 10-15 persons ask this
question in D.learn:
 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=22772

http://www.digitalmars.com/ctg/OptlinkErrorMessages.html#symbol_undefined
Nov 13 2010
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Walter Bright:

 bearophile wrote:
 A new fresh trouble, I think I have already seen about 10-15 persons ask this
question in D.learn:
 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=22772

http://www.digitalmars.com/ctg/OptlinkErrorMessages.html#symbol_undefined

Probably we'll see more people asking for that kind of help. Not all D newbies come from languages that use a linker. Today a significant and growing percentage of newbie D programmers come from Java, C#, JavaScript, Python, etc. The linker is currently present in the D world, and you can't hide this fact (but simpler to understand error messages will probably help a lot). My preferred (partial) solution to that problem is to let DMD look by itself for the modules it needs to compile a program, unless a compiler switch asks otherwise and restores the simpler basic behaviour. This helps D newbies, people that write small programs, and causes exactly zero troubles to people that compile large D programs or people that want partial compilation anyway. This doesn't solve all linker troubles, because linker errors may have other causes, but removes the most common one for D newbies and is useful for other purposes too. Bye, bearophile
Nov 13 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Andrew Wiley:

 Learning to
 operate a compiler and linker is a fundamental part of programming pretty
 much any compiled language, and taking it away encourages the user to not
 care how their code becomes an executable. To me, this seems like a large
 disservice.

Many new programmers don't want to know how to read linker mangled error messages, how to use a linker, or sometimes even what a linker is. Less and less people will want to use languages that force people to know those things. I have used Delphi for medium sized programs not caring much about its linker. If you don't even see the usefulness of more readable linker errors then... why are where here? Aren't we trying to improve older languages? :-) Bye, bearophile
Nov 13 2010
parent reply Walter Bright <newshound2 digitalmars.com> writes:
Andrew Wiley wrote:
 I interpreted this as the compiler adding modules that were unspecified 
 on the command line when calling the linker. If you meant that the 
 compiler should search for additional required modules for more useful 
 error messages, I agree with that sentiment.
 As written, it seems like you want the compiler to try to autodetect 
 which object files need to be linked together and add those objects to 
 the arguments to the linker, which I believe is a disservice because it 
 takes a simple "pure" input/output model of compilation and makes it 
 perform actions the programmer didn't necessarily intend or comprehend.

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.
Nov 13 2010
parent reply Rainer Deyke <rainerd eldwood.com> writes:
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. -- Rainer Deyke - rainerd eldwood.com
Nov 14 2010
parent Walter Bright <newshound2 digitalmars.com> writes:
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.
Nov 14 2010
prev sibling next sibling parent Andrew Wiley <debio264 gmail.com> writes:
--20cf30434516ed34060494f8edbd
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Nov 13, 2010 at 5:02 PM, bearophile <bearophileHUGS lycos.com>wrote:

 Walter Bright:

 bearophile wrote:
 A new fresh trouble, I think I have already seen about 10-15 persons





Probably we'll see more people asking for that kind of help. Not all D newbies come from languages that use a linker. Today a significant and growing percentage of newbie D programmers come from Java, C#, JavaScript, Python, etc. The linker is currently present in the D world, and you can't hide this fact (but simpler to understand error messages will probably help a lot). My preferred (partial) solution to that problem is to let DMD look by itself for the modules it needs to compile a program, unless a compiler switch asks otherwise and restores the simpler basic behaviour. This helps D newbies, people that write small programs, and causes exactly zero troubles to people that compile large D programs or people that want partial compilation anyway. This doesn't solve all linker troubles, because linker errors may have other causes, but removes the most common one for D newbies and is useful for other purposes too.

the compiler or linker change what you said to what it thinks you meant seems likely to cause unintended behavior and become a crutch. Learning to operate a compiler and linker is a fundamental part of programming pretty much any compiled language, and taking it away encourages the user to not care how their code becomes an executable. To me, this seems like a large disservice. --20cf30434516ed34060494f8edbd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Sat, Nov 13, 2010 at 5:02 PM, bearophile <spa= n dir=3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com">bearophileHUG= S lycos.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" styl= e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> Walter Bright:<br> <div><div></div><div class=3D"h5"><br> &gt; bearophile wrote:<br> &gt; &gt; A new fresh trouble, I think I have already seen about 10-15 pers= ons ask this question in D.learn:<br> &gt; &gt; <a href=3D"http://www.digitalmars.com/webnews/newsgroups.php?art_= group=3Ddigitalmars.D.learn&amp;article_id=3D22772" target=3D"_blank">http:= //www.digitalmars.com/webnews/newsgroups.php?art_group=3Ddigitalmars.D.lear= n&amp;article_id=3D22772</a><br> &gt;<br> &gt; <a href=3D"http://www.digitalmars.com/ctg/OptlinkErrorMessages.html#sy= mbol_undefined" target=3D"_blank">http://www.digitalmars.com/ctg/OptlinkErr= orMessages.html#symbol_undefined</a><br> <br> </div></div>Probably we&#39;ll see more people asking for that kind of help= . Not all D newbies come from languages that use a linker. Today a signific= ant and growing percentage of newbie D programmers come from Java, C#, Java= Script, Python, etc. The linker is currently present in the D world, and yo= u can&#39;t hide this fact (but simpler to understand error messages will p= robably help a lot).<br> <br> My preferred (partial) solution to that problem is to let DMD look by itsel= f for the modules it needs to compile a program, unless a compiler switch a= sks otherwise and restores the simpler basic behaviour. This helps D newbie= s, people that write small programs, and causes exactly zero troubles to pe= ople that compile large D programs or people that want partial compilation = anyway. This doesn&#39;t solve all linker troubles, because linker errors m= ay have other causes, but removes the most common one for D newbies and is = useful for other purposes too.<br> <font color=3D"#888888"><br></font></blockquote><div><br></div><div>I would= argue that while helpful error messages are... helpful, but having the com= piler or linker change what you said to what it thinks you meant seems like= ly to cause unintended behavior and become a crutch. Learning to operate a = compiler and linker is a fundamental part of programming pretty much any co= mpiled language, and taking it away encourages the user to not care how the= ir code becomes an executable. To me, this seems like a large disservice.</= div> </div><br> --20cf30434516ed34060494f8edbd--
Nov 13 2010
prev sibling parent Andrew Wiley <debio264 gmail.com> writes:
--001517479648e8ff520494fc2574
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Nov 13, 2010 at 9:14 PM, bearophile <bearophileHUGS lycos.com>wrote:
 If you don't even see the usefulness of more readable linker errors then...
 why are where here? Aren't we trying to improve older languages?

I said that improved error messages would be helpful. I may have misinterpreted you when you said:
My preferred (partial) solution to that problem is to let DMD look by

switch asks otherwise and restores the simpler basic behaviour. I interpreted this as the compiler adding modules that were unspecified on the command line when calling the linker. If you meant that the compiler should search for additional required modules for more useful error messages, I agree with that sentiment. As written, it seems like you want the compiler to try to autodetect which object files need to be linked together and add those objects to the arguments to the linker, which I believe is a disservice because it takes a simple "pure" input/output model of compilation and makes it perform actions the programmer didn't necessarily intend or comprehend. --001517479648e8ff520494fc2574 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Sat, Nov 13, 2010 at 9:14 PM, bearoph= ile <span dir=3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com">bearo= phileHUGS lycos.com</a>&gt;</span> wrote:<blockquote class=3D"gmail_quote" = style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <br> If you don&#39;t even see the usefulness of more readable linker errors the= n... why are where here? Aren&#39;t we trying to improve older languages?</= blockquote><div><br></div><div>I said that improved error messages would be= helpful.</div> <div>I may have misinterpreted you when you said:</div><div><br></div><div>= <span class=3D"Apple-style-span" style=3D"font-family: arial, sans-serif; f= ont-size: 13px; border-collapse: collapse; ">&gt;My preferred (partial) sol= ution to that problem is to let DMD look by itself for the modules it needs= to &gt;compile a program, unless a compiler switch asks otherwise and rest= ores the simpler basic behaviour.</span></div> <div><span class=3D"Apple-style-span" style=3D"font-family: arial, sans-ser= if; font-size: 13px; border-collapse: collapse; "><br></span></div><div><sp= an class=3D"Apple-style-span" style=3D"font-family: arial, sans-serif; font= -size: 13px; border-collapse: collapse; ">I interpreted this as the compile= r adding modules that were unspecified on the command line when calling the= linker. If you meant that the compiler should search for additional requir= ed modules for more useful error messages, I agree with that sentiment.</sp= an></div> <div><span class=3D"Apple-style-span" style=3D"font-family: arial, sans-ser= if; font-size: 13px; border-collapse: collapse; ">As written, it seems like= you want the compiler to try to autodetect which object files need to be l= inked together and add those objects to the arguments to the linker, which = I believe is a disservice because it takes a simple &quot;pure&quot; input/= output model of compilation and makes it perform actions the programmer did= n&#39;t necessarily intend or comprehend.</span></div> </div><br> --001517479648e8ff520494fc2574--
Nov 13 2010