A simple question
Adam D. Ruppe
destructionator at gmail.com
Thu Nov 15 16:53:25 PST 2012
On Friday, 16 November 2012 at 00:29:24 UTC, David Nadlinger
wrote:
> Granted, the diagnostics for it are terrible, you just get to
> see the raw linker error message.
This is potentially very easy to fix...
$ cat demangle.d
import core.demangle;
import std.stdio;
import std.regex;
string dem(Captures!(char[], uint) m) {
return demangle(m.hit).idup;
}
void main(string[] args) {
if(args.length > 1) {
foreach(arg; args[1..$])
writeln(demangle(arg));
return;
}
foreach(line; stdin.byLine) {
writeln(line.replace!dem(regex("_D[a-zA-Z0-9_]+",
"g")));
}
}
$ cat /home/me/demangle_gcc
#!/bin/bash
exec gcc $* 2>&1 | /home/me/demangle
$ export CC=/home/me/demangle_gcc
$ dmd test2.d
test2.o: In function `_Dmain':
test2.d:(.text._Dmain+0x34): undefined reference to
`_D9something1A7__ClassZ'
test2.d:(.text._Dmain+0x41): undefined reference to `something.A
something.A.__ctor(int)'
collect2: ld returned 1 exit status
A little more readable than
`_D9something1A6__ctorMFiZC9something1A'!
core.demangle apparently has some bugs, but these simple little
scripts help to beautify the linker output without actually
changing anything.
On Windows, the environment variable LINKCMD is used instead of
CC. Other than that and other little details, I'm sure the same
approach would work.
Now, append "CC=/home/me/demangle_gcc" to your dmd.conf... and
there's now no need to set the environment variable in your shell.
So if we made those demangle scripts and put them in the zip with
dmd, then changed dmd.conf to use the helper script
(CC=%@P%demangle_gcc on linux, LINKCMD=demangle_link.bat on
windows).... and there you go, demangled linker output.
A fancier script could detect things like ModuleInfo and give a
helpful hint afterwards.
More information about the Digitalmars-d
mailing list