Build a Trivial Library: Difference between revisions

From VrlWiki
Jump to navigation Jump to search
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 ...
 
No edit summary
Line 1: Line 1:
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 library.
This is an example showing how to create and build a trivial library.  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 library.


  > mkdir  foo
  > mkdir  foo
Line 50: Line 50:
  #  that are private.
  #  that are private.
  #
  #
  G_INCLUDE  foo.h
  INCLUDE_H = foo.h





Revision as of 15:54, 30 April 2010

This is an example showing how to create and build a trivial library. 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 library.

> mkdir  foo
> cd  foo


Edit a new file foo.h and add the library header declarations:

 #ifndef FOO_H
 #define FOO_H

 bool isGreater(int a, int b);

 #endif


Edit a file foo.cpp and add the library body:

 #include "foo.h"

 bool isGreater(int a, int b) {
   return (a > b);
 }


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 = foo


 # This is the name of the generated library file.
 # There can be more only one library per directory.
 #
 LIBRARY = foo


 # For C++ sources in a library set the CXXSRC variable.
 #
 CXXSRC = foo.cpp

 #  Include files to be installed.  Do not list include files
 #  that are private.
 #
 INCLUDE_H = foo.h


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


Use make to build the library. It will create the obj directory with an optimized version (libfoo-gcc4.a), a debugging version (libfoo-gcc4_g.a) and a profiling version (libfoo-gcc4_p.a). Note that on Windows the libraries will be foo-cl9.lib, foo-cl9_g.lib, and foo-cl9_p.lib.

> make
   :
> ls obj/*foo*
obj/libfoo-gcc4.a*  obj/libfoo-gcc4_g.a*  obj/libfoo-gcc4_p.a*


If you want to delete the build output run:

> make  clean