linker wrapper

spir denis.spir at gmail.com
Fri Nov 12 01:49:07 PST 2010


On Thu, 11 Nov 2010 18:28:08 -0500
bearophile <bearophileHUGS at lycos.com> wrote:

> Walter:
> 
> > 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.
> 
> What the linker is doing is something that conceptually is not complex, so an average programmer is supposed to understand what are the problems a linker may encounter in its work.
> 
> Yet clearly some newbie programmers don't understand those linker errors, this is one recent example (and I have seen two or three other similar questions):
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=22731
> 
> Quotation from that post:
> 
> > test.d:(.text._Dmain+0x9): undefined reference to `_D7libtest3funFiZi'
> > collect2: ld returned 1 exit status
> > --- errorlevel 1
> > 
> > I have no troubles with standard libraries, just mine's. I have the dmd
> > 2.0.50 compiler on a GNU/Linux 64bit system. Any idea?
> 
> A better error message is probably able to avoid similar requests for help. A better error message spares the need for the newbie D programmer to know what the linker is doing (eventually to program in D seriously you need to know why the linker is working, but asking such knowledge from day zero is not wise, especially because some future D programmer may come from JavaScript, Python, Ruby, Java, etc where there is no experience about linkers).
> 
> Recently you have modified the error messages, so this D2 program:
> 
> void main() {
>     writeln("Hello world!");
> }
> 
> Now gives an error message useful for the D newbie:
> 
> test.d(2): Error: 'writeln' is not defined, perhaps you need to import std.stdio; ?

This is really great! Thinking that way at newcomers, at their points of view, is not only nice, but probably one of the best srategies to enlarge D's adoption in the long term. People should feel welcome.

> Helping the newbie with the linker errors will be similarly useful (even better is to DMD to find its needed modules by itself on default, unless a compiler switch is used to disable this feature. I think this solves the problem. It's good for newbies, it's good for small or script-like D programs, and for more serious usages of D you just need to add the disabling switch in the command line).

But this may not be done in the general case. What if the name of the undefined symbol the programmer intends to use only happens to match one of the std lib's? (and maybe various modules of the std lib define symbols with the same names?)


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list