Saturday, January 4, 2020

Getting Started With SCons Installing and Using

SCons is a next-generation make utility that is much easier to configure and use than make. Many developers find make syntax not just difficult to get into but quite ugly. Once youve learned it, its okay, but it has a bit of a steepish learning curve. So thats why SCons was devised; its a better make and considerably easier to use. It even tries to figure out what compiler is needed and then supplies the right parameters. If you program in C or C on Linux or Windows then you should definitely check SCons. Installation To install SCons you need to have Python already installed. If you are using Linux then most likely youll have Python already. If you have Windows you can check if you already have it; some packages might have installed it already. First, get a command line. Click the start button, (on XP click Run), then type cmd and from the command line type python -V. It should say something like Python 2.7.2. Any version 2.4 or higher is ok for SCons. If you havent got Python then you need to download and install 2.7.2. Currently, SCons does not support Python 3 so 2.7.2 is the latest (and final) 2 version and the best one to use. However, that may change in the future so check the SCons requirements. Follow the instructions for installing SCons. Its not complicated; however, when you run the installer, if its under Vista/Windows 7 make sure you run the scons.win32.exe as administrator. You do this by browsing to the file in Windows Explorer and right click then Run As Administrator. Once its installed then, assuming you have any of Microsoft Visual C (Express is ok), MinGW tool chain, Intel Compiler or the PharLap ETS compiler already installed, SCons should be able to find and use your compiler. Using SCons As a first example, save the code below out as HelloWorld.c. int main(int arcg,char * argv[]){printf(Hello, world!\n);} Then create a file called SConstruct in the same location and edit it so it has this line below in it. If you save the HelloWorld.c with a different filename, make sure that the name inside the quotes matches. Program(HelloWorld.c) Now type scons at the command line (in the same place as HelloWorld.c and SConstruct) and you should see this: C:\cplus\blogsconsscons: Reading SConscript files ...scons: done reading SConscript files.scons: Building targets ...cl /FoHelloWorld.obj /c HelloWorld.c /nologoHelloWorld.clink /nologo /OUT:HelloWorld.exe HelloWorld.objscons: done building targets. This built a HelloWorld.exe which when run produces the expected output: C:\cplus\blogHelloWorldHello, world! Notes The online documentation is very good for getting you started. You can refer to the terse single file man (manual) or the friendlier more verbose SCons Users Guide. SCons makes it easy to remove unwanted files from the compilation just add the -c or -clean parameter. scons -c This gets rid of HelloWorld.obj and the HelloWorld.exe file. SCons is cross-platform, and while this article has  been about getting started on Windows, SCons comes prepackaged for Red Hat(RPM) or Debian systems. If you have another flavor of Linux, then the SCons guide gives instructions for building SCons on any system. Its open source at its best. SCons SConstruct files are Python scripts so if you know Python, then youll have no probs. But even if you dont, you only need to learn a small amount of Python to get the best out of it. Two things you should remember, though: Comments start with #You can add print messages with print(Some Text) Note that SCons is only for non-.NET, so it cant build .NET code unless you learn SCons a bit more and create a specific builder.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.