Build a Trivial Program

From VrlWiki
Revision as of 14:47, 30 April 2010 by Brad Berg (talk | contribs) (New page: 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 ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 a ".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