title: Difference between Executable and Linkable Format(.elf) and Object(.o) file
body: <p>I was looking in the gcc manual on linux (<code>man gcc</code>), for the <code>-c</code> option (<code>gcc -c infile</code>) which states:</p>
  
  <blockquote>
    <p>-c: Compile or assemble the source files, but do not link.  The linking stage simply is not done.  The ultimate output is in the form of an object file for each source file.<br>
    By default, the object file name for a source file is made by replacing the suffix .c, .i, .s, etc., with .o.</p>
  </blockquote>
  
  <p>more so, while inspecting an ELF file and an object file( with <code>file</code> comand ) the output is the same:  </p>
  
  <pre><code>file ./out/main.o: ELF 32-bit LSB relocatable, Atmel AVR 8-bit, version 1 (SYSV), not stripped
  file ./out/main.elf: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, not stripped
  </code></pre>
  
  <p>So they both have same description.
  My questions are:  </p>
  
  <ul>
  <li>What is the practical difference between both files, or in case I have multiple source file?  </li>
  <li>What is the correct file to run, and how to generate it? </li>
  <li>Do I need object files, or they are only intermediary files?</li>
  <li>If I compile some source files with <code>-c</code> option and some flags( <code>-Wall -g -std=c99 -Os</code> ) and get the object files from them, does the flags persist on ELF file generation( can I skip the flags while generating ELF file if I used them on Object files )? </li>
  </ul>