SCons D support

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 10 08:04:19 PDT 2012


On Thu, May 10, 2012 at 10:13:53AM +0100, Russel Winder wrote:
> I have started having a go at a revamp (but may turn out to be a total
> rewrite) of the SCons support for D builds. My focus is entirely on
> 64-bit Linux so unless other folk chip in, support for obscure
> platforms like Windows will be minimal ;-)
> 
> The dmd tool now works with dmd and gdmd. I have the beginnings of a
> gdc tool which works,

Yay!! I'll give it a spin sometime today and see.


[...]
> The aim is to refactor all these to create toolchain specific tools
> and that to put over the top a d_lang tool which infers a toolchain to
> use.

Makes sense to me.


> Currently the overall process is to use a D compiler to create object
> code and then use a linker to link things.  The dmd tool (from 2003
> long before I fiddled with it) seems to just use GCC as linker rather
> than using DMD or GDMD. I am still not sure if this is a good or a bad
> thing, or whether it is just that the "smart linking" code is broken.

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

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

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

Things get tricky if you start having more than 2 languages, though, so
explicit linking may be unavoidable in those cases.


> Anyone interested feel free to join in, the focus is at
> https://bitbucket.org/russel/scons_d_support
[...]

Thanks!! I'll check it out soon.


T

-- 
Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG


More information about the Digitalmars-d mailing list