linker wrapper

bearophile bearophileHUGS at lycos.com
Thu Nov 11 15:28:08 PST 2010


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

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).

Bye,
bearophile


More information about the Digitalmars-d mailing list