SCons D support

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 10 11:30:56 PDT 2012


On Thu, May 10, 2012 at 06:27:20PM +0100, Russel Winder wrote:
> On Thu, 2012-05-10 at 08:04 -0700, H. S. Teoh wrote:
> [...]
> > I can't speak for dmd, but for gdc and ldc, I think it makes sense
> > to use the system linker to do the linking. The current dmd tool is
> > very broken, it keeps insisting on appending "-lgphobos -lgphobos
> > -lgphobos" (yes it repeats thrice) to the link command for some
> > mysterious reason.  That's why I have to rewrite LINKCOM in my
> > environment
> 
> I recollect seeing this and fixing it, but mayhap only for Linux and
> OSX, 32-bit and 64-bit. Are you on Windows?

I'm on 64-bit Linux:

SCons by Steven Knight et al.:
        script: v2.1.0.r5357[MODIFIED], 2011/09/09 21:31:03, by bdeegan on ubuntu
        engine: v2.1.0.r5357[MODIFIED], 2011/09/09 21:31:03, by bdeegan on ubuntu
        engine path: ['/mnt/1/usr/lib/scons/SCons']
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 The SCons Foundation


This may be an old version of SCons, I'm not sure. It's what's currently
in the Debian repos.


> > OTOH, with languages like C++ and D, I find that sometimes the most
> > painless way to link is to invoke the compiler itself, so that any
> > hidden special libraries are automatically pulled in. For example,
> > instead of:
> > 
> > 	gdc -c src1.d src2.d
> > 	ld -o prog src1.o src2.o -L/usr/share/lib/gdc/... -lgphobos2 -l<whatever else>
> > 	# have to explicitly specify all language support libraries
> > 	# including search paths
> > 
> > just run:
> > 
> > 	gdc -c src1.d src2.d
> > 	gdc -o prog src1.o src2.o
> > 	# magically pulls in phobos, druntime, whatever else it needs
> > 	# no need to figure out search paths
> 
> Currently for reasons I don't fully understand, but I think deleting
> most of the code might help, the dmd, gdc and ldc tools all use gcc as
> the linker. I haven't worried about this till now as it worked. Now
> though is the time to attack these sorts of issue.

I have to admit I don't fully understand how SCons tool inference works.
The linker command, the arguments used by LINKCOM in particular, seem to
be black magic to me.


> > DMD works the same way, except that any linker options need to be
> > escaped with a "-L" prefix (so -lncurses becomes -L-lncurses, etc.).
> > 
> > For D projects that also have C code:
> > 
> > 	gdc -c src1.d src2.d
> > 	gcc -c src3.c
> > 	gdc -o prog src1.o src2.o src3.o
> 
> This would indicate that gdc and gcc are effectively interchangeable
> as the linker. But then given gdc is gdc this is sort of not
> surprising.
[...]

Using gcc instead of gdc on the last line will produce reams and reams
of errors about undefined symbols, unless you explicitly specify
-lgphobos2 somewhere on the commandline (and perhaps one or two other
libraries). Using gdc appears to automatically insert the requisite
arguments to the ld call so that everything Just Works.

We probably have to get our hands dirty, though, and figure out exactly
what is being passed to the linker, and how it's decided, so that the
SCons tool can do the right thing in all situations.


T

-- 
Don't get stuck in a closet---wear yourself out.


More information about the Digitalmars-d mailing list