Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:59:27+00:00 2026-05-25T09:59:27+00:00

I just started learning to use SCons, anticipating that it solves some of my

  • 0

I just started learning to use SCons, anticipating that it solves some of my issues with make. I’m creating a source hierarchy to understand the basics of SCons.

Let’s start with this folder structure:

  • test/foo: contains main.cpp, main.h
  • test/bar: contains its own main.cpp, main.h
  • test/common: contains utils.cpp and utils.h used by both foo and bar
  • test/external/moo: the source to some external library, containing ‘configure’ which produces ‘Makefile’ (not using SCons), so SCons needs to invoke ‘make’ after ‘configure’; I suspect this part might be tricky when build dirs are used
  • test/build/debug: build dir for debug
  • test/build/release: build dir for release

Here’s what I’d like to do:

  • Have two types of builds: debug/release where the only difference is that debug specifies -DDEBUG to g++

  • Use build dirs so that no .o files are created in my source tree. Let’s call these build dirs “build/debug” and “build/release”

  • Be able to invoke ./configure and make on another project that does not use SCons, followed by linking libmoo.a it produces with my project

  • Have the builds be perfectly parallel (scons -j9 for an 8-core?)

  • Have some debug/release-independent way of specifying libraries to link. Something like:

    env.Program(target='foo', source=['foo/main.cpp', '#build/(DEBUG_OR_RELEASE)/lib/libsomething.a'])
    

What would the very basic SConstruct/SConscript files to do the above look like? Even just pointers in the right directions would be great too!

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:59:28+00:00Added an answer on May 25, 2026 at 9:59 am

    I do this for builds for multiple platforms (rather than debug/release) but the concept’s the same. The basic idea is that you need 2 files in the project root – a SConstruct to set up the build directories (or “variant directories” as they are known in scons), then a SConscript that describes the actual build steps.

    In the SConstruct file you’d specify the variant directory and its corresponding source directory:

    SConscript(dirs='.',
               variant_dir=variant_dir,
               duplicate=False,
               exports="env")
    

    Now you want variant_dir to depend on a flag. You’d use AddOption or Variables to do this. Here’s one example of a complete top-level SConstruct to do that:

    # build with `scons --debug-build` for debug.
    AddOption(
        '--debug-build',
        action='store_true',
        help='debug build',
        default=False)
    
    env = Environment()
    
    if GetOption('debug_build'):
        env.ParseFlags('-DDEBUG')
        variant_dir = 'build/debug'
    else:
        variant_dir = 'build/release'
    
    SConscript(dirs='.',
               variant_dir=variant_dir,
               duplicate=False,
               exports="env")
    

    AddOption is easiest to use, but if you use Variables then you can cache the result between runs, rather than having to spell out “scons –debug-build” each time.

    All the directory setup and associated cruft is in the SConstruct. Now the SConscript file is quite simple and doesn’t need to worry about build directories at all.

    Import('env')
    
    env.Program(target='foo_prog', source=['foo/main.cpp', 'lib/libmoo.a'])
    # foo_prog since foo already exists as the name of the directory...
    

    This is about the simplest way I’ve found to set up different build directories without getting weird errors. It’s also pretty flexible – you can add different platform builds just by modifying the “env” in the top-level script without having to alter the actual meat of the build.

    The only spanner in the works in your question is the way to compile autoconf-style projects directly from SCons. The easiest way is probably with a couple of Command() calls, but SCons likes to know about the inputs and outputs of each step, so this can get hacky. Also, you have to rely on the autoconf build having a correct VPATH setup – some projects don’t work if you try and compile outside the source tree. Anyway, a way to compile autoconf projects would be something like this:

    import os
    Import('env')
    
    # get the path to the configure script from the "moo" source directory
    conf = env.File('moo/configure').srcnode().abspath
    
    # Create the "moo" build directory in the build dir
    build_dir = env.Dir('.').path
    moo_dir = os.path.join(build_dir, 'moo')
    Mkdir(moo_dir)
    
    # run configure from within the moo dir
    env.Command('moo/Makefile', 'moo/Makefile.am',
        conf, chdir=moo_dir)
    # run make in the moo dir
    env.Command('moo/libmoo.a', 'moo/Makefile',
        'make', chdir=moo_dir)
    
    env.Program(target='foo_prog', source=['foo/main.cpp', 'moo/libmoo.a'])
    

    Running the configure step from the source directory while the current working directory is somewhere in the build hierarchy is awkward. The make step is less messy, but still needs to know about the current build directory. Since you specify “libmoo.a” as an output of the make step and libmoo.a as an input to the program, all the dependencies Just Work, so a parallel build works fine. Parallel builds only break down when you fudge dependencies too much.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning C but I don't understand this part of the code.
I just started learning C++ (coming from Java ) and am having some serious
I'm stil pretty new to regular expression and just started learning to use awk.
I have just started learning Lucene and would like to use it for indexing
I've just started learning WPF and like the power of databinding it presents; that
I've just started learning how to use git today, progressing well. As an experiment,
I just really started learning how to use regex's and i am trying to
I have just started learning UML and after completing use case I've just started
I've just started learning about extending the Configuration file structure by creating custom section
I just started learning JS the other day and am (of course) having some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.