Search code examples
c++executableprogram-entry-pointscons

How to use scons to build cpp files: each file with an executable?


I've a cpp file directory having files like:

a.cpp b.cpp c.cpp xy.cpp ....

Each cpp file has a main function, so I wish to build each file into an executable. So how do I use scons to find and loop all these source files and build them each? Note that env.Glob(xxx) will build all files into one, not as I expected.

Would you kindly help to suggest?

Thanks a lot.


Solution

  • Try this:

    env=Environment()
    for f in env.Glob("*.cpp"):
      env.Program("${SOURCE.base}",f)
    

    This should make a bunch of programs named a,b,... from source files a.cpp, b.cpp...