Question

I am using Scons/Sconstruct to build a project with the following directory structure:

+A
|--A1
|--A2
+B
|--B1
  |-b1.cpp

The 'A' directory contains code which a sconstruct file in B1 refers to, as per the following scontruct file (simplified for use here):

env = Environment(CPPPATH=['.', '../../']
source_common = 'A/A1/source.cpp'
env.Program( target = 'b1_exec', source = ['b1.cpp', source_common] )

However, when compiling, I receive an error that the A/A1/source.cpp cannot be found. I would have thought adding the CPPPATH parameter would have allowed the compiler to find the source.cpp file. I seem to be going round in circles, so would very much appreciate any help.

Thanks.

Was it helpful?

Solution

One of the first rules to remember when building with SCons is that the source code to be built must be in the same directory/sub-directory as the root level SConstruct script. There are a few options you could consider:

  1. Place the SConstruct at the root directory of A and B, which would control the building of both sub-directories.

  2. Make each directory (A and B) be separate projects and each would have its own SConstruct. Then project B would refer to libraries built separately in project A.

The choice just depends on the nature of the projects and your requirements. A downside to option 2 is that if a source file in A1 or A2 changes, it wont be detected when compiling project B, since project B will only know about the libraries/headers in project A.

Regarding the CPPPATH construction variable: this variable configures the location of the header files. If this project were on Linux (or other Unix variants) with the gcc/g++ compiler, then the CPPPATH variable configures the '-I' compiler flags. Remember, when setting the CPPPATH variable, its not necessary to include the '-I' flag, SCons will add it in a platform-independently manner (meaning it will set it based on the platform and compiler being used).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top