0

I have a C++ project, and I am transitioning from Visual Studio Solutions to SCons for builds, so Linux users can also build my code. This is my first foray into SCons, and it's working very well with simple projects. But, for this project, I have a nested directory structure:

main/
  sub1/*.cpp
  sub2/*.cpp
  sub3/*.cpp
  file1.cpp
  file2.cpp

And I have the following SConstruct file:

env = Environment()
env['PCHSTOP'] = 'stdafx.hpp'
env['PCH'] = env.PCH('stdafx.cpp')[0]

env.Program('program', [
  'file1.cpp',
  'file2.cpp',
  'sub1/file1.cpp',
  'sub2/file1.cpp',
  'sub3/file1.cpp'
])

Running scons from the command line causes the following error:

fatal error C1083: Cannot open include file: 'stdafx.hpp': No such file or directory

Obviously, this is an MSVC error. But this should be solvable with Scons, I'm just not sure how..

I Noticed that Visual Studio will copy all the *.obj files to a build directory before linking by default. I think this may be part of the solution, but again, I'm unsure.

What I AM sure of, is this is not the first time someone has come across this problem, but Google didn't turn up anything for me.

PS: Unlike in the example, none of the files have naming conflicts, and could theoretically be moved to a flattened folder structure by SCons without issue.

Adam Becker
  • 573
  • 4
  • 5

1 Answers1

0

This looks like you'll have to specify the proper include paths in your Environment via the "CPPPATH" variable...but it's difficult to tell without seeing the full command line. Remember, that all SCons envs are clean initially. So, if you're in the wrong working directory, a simple "#include " doesn't find the header if it's in a different folder. Have a look at SCons' UserGuide, chap. 14 "Hierarchical Builds", which might give you a few more ideas and insights, or come over to the User mailing list at scons-users@scons.org.

dirkbaechle
  • 3,984
  • 14
  • 17
  • Set up a test environment at work, and setting `CPPPATH` seems to be the answer. I'll try when I get home and mark this as the answer if it works there too. – Adam Becker Oct 09 '14 at 16:11