spot
This section will introduce:
The red line of this section is the implementation - in C++ - of an application reading files holding either a complete image or the definition of shapes which will be used later on during the hands-on session.
Such an image file can be found there while a file storing shapes can be found here. You should look at these files to familiarize yourself with their structure.
This first steps allows you to define and create your workarea with a tool to automatize tasks.
Structure and layout of your workarea:
$> cd
$> mkdir Project
Throughout this hands-on session, you should make sure to properly organize your workarea by creating -if necessary- proper directories. This allows to isolate and decouple development areas from one another, minimize naming conflicts (e.g. files automatically generated by some tools with the same name) and this dramatically eases groking the overall structure of the project.
One could also create a directory Project/Tests in which one would quickly evaluate and test a snippet of code extracted from the documentation.
This step illustrates the simple development cycle of an application
After having bootstrapped the workarea environment, this cycle holds the following steps:
Generally speaking, the life cycle of an application can be described by cyclically iterating through the above mentionned steps. For example, the typical cycle consists in doing 1 (once) and then the sequence (2,3,4) in a loop.
Firstly, go under your work directory Project.
$> cd ~/Project
Warning
all your work shall happen under this Project directory (or one of its subdirectory.)
We will then setup a workspace with CMT dedicated to this exercize. This workspace shall be named Hello.
$> cmt create Hello v1
------------------------------------------
Configuring environment for package Hello version v1.
CMT version v1r20p20090520.
Root set to /Users/visiteur/tests.
System is Darwin
------------------------------------------
Installing the package directory
Version directory will not be created due to structuring style
Installing the cmt directory
Installing the src directory
Creating setup scripts.
Creating cleanup scripts.
Warning
a cmt directory has been created as a side-effect of running the cmt create command. All the remaining work of this exercize shall be caried from under that directory.
$> cd Hello/cmt
We will copy the program given in example below under the directory ../src of our workspace previously created. This will became a hello.cpp file.
After a close inspection of the sources, we notice it is the classical program which displays a simple message on the screen. For the moment, you shouldn’t try too hard to understand what is performed on each line of this program.
/**
* @file hello.cpp
* @author LAL ens <ens@lal.in2p3.fr>
* @date March 2007
*
* First steps with a development environment.
* First program hello.cpp: display "Hello!" on standard output.
*/
#include <iostream>
int main(int argc, char **argv)
{
std::cout << "Hello!" << std::endl;
return 0;
}
Nevertheless, you should notice:
The application building proper will be handed over to CMT which will be tasked with correctly configuring and activating a tool named make.
The means to this end is the requirements file which describes the application we want to build. Edit this file and add the following line:
application hello hello.cpp
We can now ask CMT to run make. CMT will automatically take care of producing the needed configuration components used by make.
CMT configuration w.r.t your environment:
# issue this only once, for each new project
$> cmt config
Initialize CMT:
# issue this everytime you modify the CMT environment
$> source setup.sh
Building:
$> cmt make
#CMT---> Info: Execute action make => make bin=../Darwin/
#CMT---> (Makefile.header) Rebuilding ../Darwin/Darwin.make
#CMT---> (Makefile.header) Rebuilding ../Darwin/setup.make
#CMT---> (Makefile.header) Rebuilding ../Darwin/constituents.make
#CMT---> (constituents.make) Rebuilding library links
#CMT---> (constituents.make) all done
#CMT---> (constituents.make) Building hello.make
#CMT---> Info: Application hello
#CMT---> (constituents.make) Starting hello
#CMT---> (hello.make) Rebuilding ../Darwin/hello_dependencies.make
#CMT---> compiling ../src/hello.cpp
#CMT---> building application ../Darwin/hello.exe
#CMT---> hello ok
#CMT---> (constituents.make) hello done
#CMT---> all ok.
We’ll modify the hello.cpp file by introducing a while loop which will display the previous welcome message until a correct answer is given. This correct answer will terminate the program.
A few more precisions, in addition to these informations:
The building and testing of the application is performed as in the previous stage.
You should make sure to update the comments inside the program.
Typically, one should get the following output:
$> ../Darwin/hello.exe
Hello!
continue? yes
Hello!
continue? yes
Hello!
continue? yes
Hello!
continue? yes
Hello!
continue? no
Bye.