In this lecture, I'll show you how to compile software from source code using a hands on approach. 1
Let's see what are the prerequisites! Typically at your job 2
you'll need to compile servers 3
and these are programmed mostly in C and C++ programming languages for maximum efficiency. 4
To be able to compile the source code, you need the GNU Compiler Collection (GCC) 5
which is a collection of compilers and libraries for C, C++ and Objective-C. 6
The default Ubuntu repositories contain a metal package named build-essential that contains the compilers 7
and lots of libraries, as well as other utilities required for compiling software. 8
Using apt, I'm installing build essential on Ubuntu. 9
sudo apt update && sudo apt install build-essential 10
This will install in fact plenty of other packages including gcc, g++ and make. 11
I've already done it before. 12
gcc is the GNU C Compiler, g++ is the gnu c++ compiler and make is a utility used to build 13
a collection of source files and transform them into the final product. 14
If you are running CentOS then there’s a package group called “Development Tools” that contains all 15
the required components. On Centos 16
I am installing development tools sudo dnf group install "Development Tools" 17
It will install in fact plenty of other packages as dependencies. 18
We'll start by compiling a single C source file and then we'll compile a more complex application. I'm 19
creating a basic Hello application in C. Using vim 20
I'm creating a file with .c extension and pasting the following code. 21
hello .c 22
This is the typical structure of a very basic C program. 23
I'm saving the file and then compiling it into an executable. 24
Compiling means transforming the source code, which is human readable, into machine code. 25
So gcc the source fie 26
-o the binary hello; the command has created a binary file called hello in the current working 27
directory. 28
This is the executable file I've just compiled. 29
Let's run it. 30
./ 31
hello 32
hello world 33
You've just seen that compiling a single source file is very easy.