What is a Program?
- Set of instructions and data using a programming language.
What is an Application?
- Executable file stored in hard drive. ex: vlc player in the download folder.
What is Process?
- An application running in the RAM. ex: Use Google Chrome for web browsing.
What is a compiler?
- The compiler is the software that processes programs written using a programming language and converts them into the executable(low-level/machine-level) which CPU can understand.
- As shown in the image Source code is the input to the compiler and executable or Application is the output of the compiler.
What is a loader?
- Loader is the utility software that loads Application/Executable stored into the SDD to the RAM for the execution.
What is a Native Compilation?
- Compiled and executed on the same machine.
- As shown above, Visual Studio is a code editor/compiler running on an intel machine, and the executable will also run on an intel machine.
- If an executable is created for the same machine where the compiler is also running called a Native compilation.
What is Cross-Compilation?
- Compiled and executed on the different machine.
- As shown above, Visual Studio is a code editor/compiler running on an intel machine, and the executable will run on an ARM machine.
- If the machine where the compiler is running and the machine where the executable will run are different then it is called cross-compilation.
GCC Compiler.
- GNU compiler collection is an open-source compiler.
- gcc – GNU project C and C++ compiler
- find more information on the manual page.
- Below are the commands to install gcc on a Linux OS system.
- gcc for c language: sudo apt-get install gcc
- gcc for c++ language: sudo apt-get install g++
Compile a program using GCC.
- The below program is written using vim editor in linux system.
- Command to install vim : sudo apt-get install vim
- find more information about vim here.
//hello_embeddedkerenel.c
#include<stdio.h>
int main()
{
printf("Hello from Embedded kernel\n");
}
-File name is hello_embeddedkernel.c
-Command to compile above file is:
gcc embeddedkernel.c
-This command will generate executable with default name "a.out" as shown below.
a.out is present in some directory, Assume it's present in /home/ek/practice/a.out
ek@ek /home/ek/practice/ > ls -l
-rwxr-xr-x@ 1 ek usr 33432 Mar 28 01:00 a.out
-rw-r--r--@ 1 ek usr 75 Mar 28 01:08 hello_embeddedkernel.c
-To run a.out from any directory, mention whole directory(where a.out is present) and a.out as shown below.
ek@ek /home/ek/practice/ > /home/ek/practice/a.out
Hello from Embedded kernel
-Another way is go to /home/ek/practice/(where a.out is present) and type "./a.out" to run as shown below.
ek@ek /home/ek/practice/ > ./a.out
Hello from Embedded kernel
-system doesn't know where a.out is present. So, either need to provide whole directory or link to it's own directory using './'
-if only a.out is provided then it will not run and give error that "a.out: command not found" as shown below.
ek@ek /home/ek/practice/ > a.out
bash: a.out: command not found
-So, need to provide link to it's own directory or whole directory where a.out is present in order to execute binary(executable/Application).
-To compile a program with custom o/p file name. Use -o option and give any custom name for executable as shown below.
gcc embeddedkernel.c -o embeddedkernel.exe
-To run embeddedkernel.exe, same as a.out
ek@ek /home/ek/practice/ > /home/ek/practice/embeddedkernel.exe
Hello from Embedded kernel
ek@ek /home/ek/practice/ > embeddedkernel.exe
Hello from Embedded kernel
How commands are executed(runs) in linux?
- Commands of Linux are nothing but executable files which are present in the system path.
- The system path contains addresses of directories where commands are present.
- When we write a command in the command prompt (often called shell or bash – bourne again shell) it searches for that command in directories present in the system path. So that we do not have to write the command’s entire path to execute it.
- But in the case of our user-developed binaries, we have to provide a link to its directory or write the entire path to execute it. When we don’t provide a path or link, the shell assumes that the user wants to execute that command and searches for it in the system path, but as that command is not found, it shows an error message as shown above.
- To see the system path type echo $PATH in the command prompt.
- click here to see the Linux command list.