• Active Topics 

Install C, C++ Compiler and Development (build-essential) Tools in Linux-based Distributions

User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

We explain how to install C and C++ compilers[/url] and it’s development tools (build-essential), related packages: make, libc-dev/libc6-dev, dpkg-dev, and so on, in Debian and its derivatives (e.g., Ubuntu-Linux and Linux Mint), look here for some other Linux-based distributions.

Compiler is a software program that processes instructions written in a programming language and translates these instructions into a binary file that the computer’s CPU can understand and process/execute.

On the other hand, the build-essential software contains an informational list of software considered to be important for building Debian packages, including gcc compiler, make and other required tools. GCC (GNU Compiler Collection) and G++ (GNU C++ Compiler) compilers are the most well-known C and C++ compilers, respectively, for Linux-based distributions. These compilers were developed by the Free Software Foundation through the GNU (GNU's Not Unix!) project. To-date, the Free Software Foundation continues to maintain these program software. GCC is usually installed by default in Debian and its derivatives, however, all GNU/Linux distributions include packages for GCC.

You can install the latest available version of build-essential from the default distribution repositories by opening the Terminal and typing (remember to hit ENTER button):

Code: Select all

sudo apt-get update
sudo apt-get install build-essential
Note: You may need to change the commands above appropriately depending on your Linux-distribution.

To run the C or C++ program, open the Terminal, navigate to the folder where your program resides, assuming your program name is program.c (C program) and program.cpp (C++ program), type respectively,

For C program:

Code: Select all

 gcc program.c -o program #Compile the program
./program #Execute/run the program

and similarly for C++ program:

Code: Select all

 g++ program.cpp -o program
./program
Here, -o option specifies the file name of the output program. It is not necessary for the file name of the source program to be the same as that for the output program. In our case above, we could specify a different file name for the output:

Code: Select all

gcc program.cpp -o outputfile
./outputfile
However, to speed up C and C++ code compilations, it is recommended to install a tool like ccache - a compiler cache for C and C++. ccache speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.

To install ccache, execute

Code: Select all

sudo apt-get install ccache
C is a low-level programming language originated in 1972. C is often portrayed as "lingua franca" of operating systems, kernels, and heavily used in systems software programming. It is valued for its high-performance, particularly, on large sizes of inputs, and for other many superior capabilities.

C++ emerged nearly a decade after C, and was developed with the goal of adding object-oriented programming features to C in mind. Its current form is often suited in embedded systems development, stunning game programming, mobile and desktop applications development, and anything related to interfacing software with hardware. Like C, C++ is favoured for its high-performance computing, particularly on large scales, and for other many technological applications. C++ is often treated as the "lingua franca" of desktop applications.

In summary, C and its extension, C++ are very useful and powerful for development areas related to machine systems such as kernels, computer application programs, and for solving complex problems due to their well-known high performance computing capabilities. However, C++ has currently found a lot of applications in web developments, especially, back-end programming.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

How robust is CLion, C and C++ IDE?

https://www.jetbrains.com/clion/
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply

Return to “C & C++ Programming”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest