What is the Difference Between Object File and Executable File

The main difference between object file and executable file is that an object file is a file generated after compiling the source code while an executable file is a file generated after linking a set of object files together using a linker.  

C is a general-purpose, high-level programming language. Moreover, it is a structured programming language that helps to write efficient programs. Operating systems, language compilers, text editors, network drivers, databases are some applications of C programming language. Object File and Executable File are two files related to C programming.

Key Areas Covered

1. What is Object File
     – Definition, Functionality
2. What is Executable File
     – Definition, Functionality
3. What is the Relationship Between Object File and Executable File
     – Outline of Association
4. What is the Difference Between Object File and Executable File
     – Comparison of Key Differences

Key Terms

C Language, Executable File, Object File

Difference Between Object File and Executable File - Comparison Summary

What is Object File

First of all, C program is a set of instructions written in C programming language to perform a specific task. This program is called the source code. The programmer can read and understand the source code, but the CPU does not understand it. Therefore, it is necessary to convert the source code into a machine-understandable format. An object code is generated after compiling the source code.

Difference Between Object File and Executable File

Figure 1: Source Code

Object file is another name for object code. The object file has the .obj extension in Windows environment. Moreover, the object file has the. o file extension in Linux environment. However, the CPU cannot directly execute the object file.

What is Executable File

After writing the C program, if there are any syntax errors, the programmer should edit them. However, if there are no syntax errors, the compiler converts the source code into an object file. Then the linker performs the linking process. It takes one or more object files generated by the compiler and combines them into a single executable file. Furthermore, it links the other program files and functions the program requires. For example, if the program has the “exp ()” function, the Linker links the program with the math library of the system.

Main Difference - Object File vs Executable File

Figure 2: Creating an Executable File

The programmer does not understand the instructions in the executable file, but the CPU can read and understand those instructions. Therefore, the CPU  directly executes the executable file to perform the defined tasks in the program.

Relationship Between Object File and Executable File

  • Object files combine together to create an executable file.

Difference Between Object File and Executable File

Definition

An object file is a file that contains an object code that has relocatable format machine code which is not directly executable. An executable file is a file that can be directly executed by the computer and is capable of performing the indicated tasks according to the encoded instructions. Hence, this explains the main difference between object file and executable file.

Type

Another difference between object file and executable file is that an object file is an intermediate file but, an executable file is a final file.

Functionality

Moreover, the compiler converts the source code to an object file. However, linker links the object files with the system library and combines the object files together to create an executable file.

Direct Execution by CPU

Also, the CPU cannot directly execute the object file while the CPU can directly execute an executable file. Thus, this is a major difference between object file and executable file.

Conclusion

In conclusion, Object File and Executable File are two files related to C programming. The main difference between object file and executable file is that an object file is a file that is generated after compiling the source code while an executable file is a file that is generated after linking a set of object files together using a linker. 

Reference:

1. “Linker (Computing).” Wikipedia, Wikimedia Foundation, 6 Oct. 2018, Available here.

Image Courtesy:

1. “Source code in C” By Romainhk – Own work (image and code) (CC BY-SA 3.0) via Commons Wikimedia
2. “C language building steps” (CC BY-SA 3.0) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply