How do I set Makefile to compile C or C++ program?

A executable (i.e. program) is obtained linking one or more C or C++ files and/or library files. An executable is characterized by:

  • one or more C or C++ source files in the src/ directory. One file is the main and, normally, there is one file for each routine.
  • standard or special compilation flags
  • one or more library, either belonging to the current module or from the external environment, i.e., other modules, products and the operating system.
  • standard or special link flags

To create a new program, insert the name of the program in one of the two lists:

   EXECUTABLES   = exe1 exe2 ..... 
   EXECUTABLES_L = exe3 .....
as appropriate; EXECUTABLES contains the list of public programs which will be installed in $INTROOT, in opposite EXECUTABLES_L contains local programs to the module. For each program, add the following set of variables:

   <exe-n>_OBJECTS = obj1 obj2 ..... .....
the list of objects needed to build the executable.
ALERT! ONLY THE FILE NAME MUST BE SPECIFIED (no extension, no dir!).
ALERT! If not defined or empty, the standard rule is not applied.

   <exe-n>_LDFLAGS = 
additional flags in linking this program (optional)

   <exe-n>_NOSHARED= 
if defined, shared libraries are not used (optional).
ALERT! REMARK: defining MAKE_NOSHARED, all executable are build without shared libraries

   <exe-n>_LIBS    =
the list of the NAME of the libraries (optional).
ALERT! ONLY THE NAME MUST BE SPECIFIED (no "-l", no ".a"!)
In this list, special names may appear, to tell Makefile to execute some specific actions. The names are:
  • MCS : the executable is linked to MCS libraries.
  • C++ : the executable is linked to C++ libraries.

The following example gives the generation of a C program myProgC and a C++ program myProgCpp. The source files of these programs are respectively myMainC(.c) and myFunction(.c), and myMainCpp(.C or .cpp) and myClass(.C or .cpp). They are both using the MCS libraries.

   #
   # C or C++ programs (public and local)
   # -----------------------------
   EXECUTABLES     = myProgC myProgCpp
   EXECUTABLES_L   = 

   #
   # C program 
   myProgC_OBJECTS   = myMainC myFunction
   myProgC_LDFLAGS   =
   myProgC_LIBS      = MCS

   #
   # C++ program 
   myProgCpp_OBJECTS   = myMainCpp myClass
   myProgCpp_LDFLAGS   =
   myProgCpp_LIBS      = MCS C++
-- GerardZins - 01 Sep 2004
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2007-02-22 - TWikiAdministrator
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback