Search code examples
scons

how to export variable correctly in SConstript


I have a directory:

src
   sconscript
   main
       sconstruct
       main.cpp

In the sconscript, I write

env=Environment(CXX='g++',LINK='g++')

In the sconstruct, I write

SConscript('../sconscript',exports='env')
Import('env')
env.Program(target='a.out',source='main.cpp')

And then I go to directory src/main and type scons -Q, it just complains:

Export of non-existent variable ''env''

From http://scons.org/doc/HTML/scons-user.html#idm139837640372096, I think the syntax is correct. So what is the problem?

I use ubuntu 16.04, Python 2.7.12 and scons 2.5.0


Solution

  • Your SConscript should read

    env=Environment(CXX='g++',LINK='g++')
    Return('env')
    

    Your SConstruct should read

    env = SConscript('../sconscript')
    env.Program(target='a.out',source='main.cpp')
    

    Take a look at the manpage: http://scons.org/doc/production/HTML/scons-man.html