Skip to main content
Engineering LibreTexts

17.3: Updated Compilation Commands

  • Page ID
    54375
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    For a large program that is split between multiple source files, the compilation process must be updated. The compilation process refers to the steps required to compile the program into a final executable file. Each module unit must be compiled independently. This allows the programmer to focus on one module, or set of routines, at a time. Further, for very large projects, multiple programmers can work on separate modules simultaneously.

    The initial step is to compile each module. Assuming the module from the earlier section is named stats.f95, the command to compile a module is:

    gfortran -c stats.f95
    

    which will read the source file (stats.f95) and create two new files: an object file stats.o and a module file stats.mod. The name of the object file is based on the name of the source file. The name of the module file is based on the module name. While they are the same name in this example, that is not a requirement.

    The compile command is required for each module.

    Once all the modules are compiled and the .o and .mod files are available, the main file can be compiled. This step reads the .o and .mod files for each module and builds the final executable file. For example, the command to compile the main file for the previous array average example is:

    gfortran -o main main.f95 stats.o
    

    For multiple modules, each of the .o files would be listed. In this example, the stats.mod file is read by the gfortran compiler. While not explicitly listed, the .mod files are required and used at this step.


    This page titled 17.3: Updated Compilation Commands is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?