Build a Trivial Program: Difference between revisions

From VrlWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 43: Line 43:
  include  $(G)/common/build/make/directory.make
  include  $(G)/common/build/make/directory.make
</pre>
</pre>


Use '''make''' to build the program.  It will create the obj directory with an optimized version (testprog-gcc4), a debugging version (testprog-gcc4_g) and a profiling version (testprog-gcc4_p).  Note that on Windows the programs will have "cl9" for the compiler id and an ".exe" suffix.
Use '''make''' to build the program.  It will create the obj directory with an optimized version (testprog-gcc4), a debugging version (testprog-gcc4_g) and a profiling version (testprog-gcc4_p).  Note that on Windows the programs will have "cl9" for the compiler id and an ".exe" suffix.

Latest revision as of 14:50, 30 April 2010

This is an example showing how to create and build a trivial program. First your account, environment and sandbox need to be established. After that you can create and build programs in any directory. First create a directory for your test program.

> mkdir  testprog
> cd  testprog


Edit a new file testprog.cpp and add this program:

 #include <stdio.h>

 int main(int argc, char **argv)
 {
   printf("hello world\n");
   return 0;
 }


Edit another file named Makefile and add:

 # The project name is used to create directory names.  For consistency
 # make this the same name as the top level directory for the project.
 #
 PROJECT = testprog

 # This is the name of the generated executable file.
 # There can be more than one program listed per directory.
 #
 PROGRAM = testprog


 # For each program with C++ sources set a variable using the program name.
 # By convention the source file containing the "main" entry point has the
 # same name as the program.
 #
 CXXtestprog = testprog.cpp


 # This brings in the G Build make files and is required.
 #
 include  $(G)/common/build/make/directory.make


Use make to build the program. It will create the obj directory with an optimized version (testprog-gcc4), a debugging version (testprog-gcc4_g) and a profiling version (testprog-gcc4_p). Note that on Windows the programs will have "cl9" for the compiler id and an ".exe" suffix.

> make
   :
> ls obj/test*
obj/testprog-gcc4*  obj/testprog-gcc4_g*  obj/testprog-gcc4_p*


You can then run the program with:

> obj/testprog-gcc4
hello world


If you want to delete the build output run:

> make  clean