SCons D tool: need help with building static library

Russel Winder russel at winder.org.uk
Mon Dec 17 10:32:57 PST 2012


On Sat, 2012-12-15 at 11:19 -0800, H. S. Teoh wrote:
[…]
> But I have trouble when I try to link to it. For some reason, the dmd
> link command isn't picking up the value of LIBPATH, so the linker can't
> find the library. Here's a reduced test case:
> 
> 	#!/usr/src/scons/russel/scons_d_tooling/bootstrap.py -f
> 	env = Environment(
> 		DC = '/usr/src/d/dmd/src/dmd',
> 	)
> 	env.Library('mylib', 'mylib.d')
> 
> 	prog_env = env.Clone(
> 		LIBS = ['mylib'],
> 		LIBPATH = '#'
> 	)
> 	prog_env.Program('prog', 'prog.d')
> 
> Output:
> 
> 	scons: Reading SConscript files ...
> 	scons: done reading SConscript files.
> 	scons: Building targets ...
> 	/usr/src/d/dmd/src/dmd -I. -c -ofmylib.o mylib.d
> 	ar cr libmylib.a mylib.o
> 	ranlib libmylib.a
> 	/usr/src/d/dmd/src/dmd -I. -c -ofprog.o prog.d
> 	/usr/src/d/dmd/src/dmd -ofprog prog.o -L-lmylib
> 	/usr/bin/ld: cannot find -lmylib
> 	collect2: error: ld returned 1 exit status
> 	--- errorlevel 1
> 	scons: *** [prog] Error 1
> 	scons: building terminated because of errors.
> 
> This works correctly when using the C compiler (SCons correctly inserts
> a "-L." in the link command).

Can you set out that case and the correct command line? I have to admit
DMD/LDC flags often confuse me, I must be a GDC/GCC person ;-)

> //
> 
> Also, an unrelated issue: if DC isn't specified and no D compiler is
> found in $PATH, it produces a rather odd command line:
> 
> 	scons: Reading SConscript files ...
> 	scons: done reading SConscript files.
> 	scons: Building targets ...
> 	I. -c -ofprog.o prog.d
> 	sh: 1: I.: not found
> 	ofprog prog.o -L-lmylib
> 	sh: 1: ofprog: not found
> 	scons: done building targets.
> 
> This is not a big deal, but it'd be nice if the tool gave a more helpful
> message along the lines of "I can't find a D compiler, please specify
> one", instead of producing a mangled command. :-)

Actually this is a big deal. If none of dmd, gdc, ldc2 are found then
the build should fails before trying a command.  Isn't this why exists
exists.  Also the generate should fail if there is no D compiler.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121217/1db8b712/attachment.pgp>


More information about the Digitalmars-d mailing list