SCons D tool: need help with building static library

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Dec 17 11:08:00 PST 2012


On Mon, Dec 17, 2012 at 06:32:57PM +0000, Russel Winder wrote:
> 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 ;-)

I'm a GDC/GCC person as well. :-) Except that GDC for my platform is
horribly outdated, so I've had to resort to DMD for my newer projects.
Plus, sometimes I'm testing fixes for Phobos, which often requires the
latest git dmd to even compile.

Anyway.  The command is missing a "-L-L." option. It should read:

	/usr/src/d/dmd/src/dmd -ofprog prog.o -L-L. -L-lmylib

which passes a "-L." option to the linker to make it search the current
directory for the library.


[...]
> > 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.
[....]

True.


T

-- 
Question authority. Don't ask why, just do it.


More information about the Digitalmars-d mailing list