Scons doesn't build a simple D program on OSX

I get an error when I try to use Scons to create a simple D file. I tested scons by building a simple helloworld.c, but the equivalent in D just doesn't happen and I'm not smart enough about Scons to know if it's a bug or a problem with my setup.

The error I am returning is ld: library not found for -lphobos

My SConstruct file:

SConscript('SConscript', variant_dir='release', duplicate=0, exports={'MODE':'release'})
SConscript('SConscript', variant_dir='debug', duplicate=0, exports={'MODE':'debug'})

      

My SConscript file:

env = Environment()
env.Program(target = 'helloworld', 
            source = ['hello.d'])

      

hello.d

import std.stdio;

void main() {
  writeln("Hello, world!");
}

      

EDIT:

Full scons output:

MyComputer:thedbook me$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: release debug
gcc -o debug/helloworld debug/hello.o -L/usr/share/dmd/lib -L/usr/share/dmd/src/druntime/import -L/usr/share/dmd/src/phobos -lphobos -lpthread -lm
ld: library not found for -lphobos
collect2: ld returned 1 exit status
scons: *** [debug/helloworld] Error 1
scons: building terminated because of errors.

      

The reason I'm puzzled is that file creation is usually dead easy (that's one thing with the helloworld file):

$ dmd hello.d -v
binary    dmd
version   v2.058
config    /usr/bin/dmd.conf
parse     hello
importall hello
... <significant amount of imports here> ...
code      hello
function  D main
function  std.stdio.writeln!(string).writeln
function  std.stdio.writeln!(string).writeln.__dgliteral834
function  std.exception.enforce!(bool,"/usr/share/dmd/src/phobos/std/stdio.d",1550).enforce
gcc hello.o -o hello -m64 -Xlinker -L/usr/share/dmd/lib -lphobos2 -lpthread -lm 

      

Note that I had to include verbosity in the compiler to show it anything. He was usually silent and linked the file.

+3


source to share


1 answer


After I figured out what the message gave me thanks to the comment, I played around with the config files a bit and got the result I wanted. I feel like this is a workaround that undermines the "cruise control" that Sconsers is going to do, but I have a build so I can't complain.

I had to change my SConscript file like this:



env = Environment()
target       = 'helloworld'
sources      = ['hello.d']
libraries    = ['phobos2', 'pthread', 'm']
libraryPaths = ['/usr/share/dmd/lib', 
                '/usr/share/dmd/src/druntime/import', 
                '/usr/share/dmd/src/phobos']

env.Program(target = target, 
            source = sources,
            LIBS = libraries,
            LIBPATH = libraryPaths)

      

The key change here is the addition of LIBS and explicitly defining which libraries to include, rather than relying on SCons to figure it out. Unfortunately, the moment you add it, you must explicitly link them all. However, I hope this helps anyone looking to get up and running quickly with D and SCons.

+4


source







All Articles