*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: <verbatim> EXECUTABLES = exe1 exe2 ..... EXECUTABLES_L = exe3 ..... </verbatim> 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: <verbatim> <exe-n>_OBJECTS = obj1 obj2 ..... ..... </verbatim> the list of objects needed to build the executable.<BR> %X% ONLY THE FILE NAME MUST BE SPECIFIED (no extension, no dir!).<BR> %X% If not defined or empty, the standard rule is not applied. <verbatim> <exe-n>_LDFLAGS = </verbatim> additional flags in linking this program (optional) <verbatim> <exe-n>_NOSHARED= </verbatim> if defined, shared libraries are not used (optional).<BR> %X% REMARK: defining MAKE_NOSHARED, all executable are build without shared libraries <verbatim> <exe-n>_LIBS = </verbatim> the list of the NAME of the libraries (optional).<BR> %X% ONLY THE NAME MUST BE SPECIFIED (no "-l", no ".a"!) <BR> 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. <verbatim> # # 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++ </verbatim> -- Main.GerardZins - 01 Sep 2004
This topic: Jmmc/Software
>
JmmcMcsFaq
>
JmmcMcsFaqMakefileCProgram
Topic revision: r2 - 2007-02-22 - TWikiAdministrator
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback