next up previous contents index
Next: Using Makefiles Up: Invocation Previous: A First Example   Contents   Index

Building Larger Programs

In case of larger programs which consists of multiple modules care is to be taken regarding the inter-module dependencies. If, for example, module A imports module B, the definition module of B must be compiled before A or B may be compiled. Whenever the definition module of B changes, all importing modules and the implementation module of B must be compiled again.

Let, for example, Main be a program module which imports Lib. Then we can compile all associated sources Main.m2, Lib.d, and Lib.m2 in one rush:

m2c -o main Lib.d Main.m2 Lib.m2

or step by step:

m2c Lib.d
m2c -c Main.m2
m2c -c Lib.m2
m2c -o main Main.o Lib.o

The option -c causes m2c to suppress the loading phase and to leave object files behind (in this example Main.o and Lib.o). The last command combines both object files to the final binary main.

Note that it does not matter whether Main.m2 or Lib.m2 is compiled first - you have only to assure that Lib.d gets compiled before one of the importing modules (here Main.m2) or the associated implementation (here Lib.m2) is processed by the compiler.


next up previous contents index
Next: Using Makefiles Up: Invocation Previous: A First Example   Contents   Index
Andreas Borchert 2003-12-10