SCons D tool: need help with building static library
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Dec 15 11:19:50 PST 2012
On Sat, Dec 15, 2012 at 06:42:45PM +0000, Russel Winder wrote:
> On Thu, 2012-12-13 at 14:49 -0800, H. S. Teoh wrote:
> > Hi Russel,
> >
> > I've been using your BitBucket scons_d_tooling version of SCons for
> > my D projects, and it's been great! However, I needed to make a
> > static library today and I'm having some trouble with it. Here's a
> > reduced testcase:
[...]
[...]
> I entered a variant of your code as a test and made the smallest
> possible change to make things work on Linux. This is untested on OS X
> or Windows.
>
> The LDC test fails for reasons I cannot suss just now, the DMD and GDC
> tests pass.
>
> I have no doubt this is a hack patch, it all needs to be sorted
> properly.
[...]
Thanks! I can build the static library now.
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).
//
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. :-)
T
--
It's amazing how careful choice of punctuation can leave you hanging:
More information about the Digitalmars-d
mailing list