{"id":11811,"date":"2019-03-17T11:56:06","date_gmt":"2019-03-17T11:56:06","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11811"},"modified":"2019-03-17T11:56:06","modified_gmt":"2019-03-17T11:56:06","slug":"install-c-c-compiler-and-development-build-essential-tools-in-debian-ubuntu","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/17\/install-c-c-compiler-and-development-build-essential-tools-in-debian-ubuntu\/","title":{"rendered":"Install C, C++ Compiler and Development (build-essential) Tools in Debian\/Ubuntu"},"content":{"rendered":"<p>Most Linux system administrators and engineers are required to know some basic programming to help them in their daily tasks. If they want to go one step further into the development area as well (either as kernel or application programmers), then\u00a0<strong>C<\/strong>\u00a0or\u00a0<strong>C++<\/strong>\u00a0is the best place to start.<\/p>\n<div id=\"attachment_15934\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-C-Compiler-Build-Essential-Tools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15934\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-C-Compiler-Build-Essential-Tools-620x293.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-C-Compiler-Build-Essential-Tools-620x293.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-C-Compiler-Build-Essential-Tools-520x245.png 520w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-C-Compiler-Build-Essential-Tools.png 720w\" alt=\"Install C, C++ Compiler and Build Essential Tools\" width=\"620\" height=\"293\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install C, C++ Compiler and Build Essential Tools<\/p>\n<\/div>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-c-c-compiler-and-development-tool-in-centos-fedora-redhat\/\" target=\"_blank\" rel=\"noopener\">Install C, C++ and Development Tools in RHEL\/CentOS\/Fedora<\/a><\/p>\n<p>In this article we will explain how to install\u00a0<strong>C<\/strong>\u00a0and\u00a0<strong>C++<\/strong>\u00a0compilers and it\u2019s\u00a0<strong>Development Tools<\/strong>\u00a0(<strong>build-essential<\/strong>) related packages such as make, libc-dev, dpkg-dev, etc. in Debian and derivatives such as\u00a0<strong>Ubuntu<\/strong>\u00a0and\u00a0<strong>Linux Mint<\/strong>.<\/p>\n<p>The\u00a0<strong>build-essential<\/strong>\u00a0software contains an informational list of software\u2019s which are treated as important for building Debian packages including gcc compiler, make and other needed tools.<\/p>\n<h3>\u200bWhat is a Compiler?<\/h3>\n<p>Simply put, a compiler is a software program that processes instructions written in a programming language and creates a binary file that the machine\u2019s CPU can understand and execute.<\/p>\n<p>In Debian-based distributions, the most well-known\u00a0<strong>C<\/strong>\u00a0and\u00a0<strong>C++<\/strong>\u00a0compilers are\u00a0<strong>gcc<\/strong>\u00a0and\u00a0<strong>g++<\/strong>, respectively. Both programs were developed and are still maintained by the\u00a0<strong>Free Software Foundation<\/strong>\u00a0through the\u00a0<strong>GNU<\/strong>\u00a0project.<\/p>\n<h3>\u200bInstalling C, C++ Compiler and Development Tools (build-essential)<\/h3>\n<p>If your system don\u2019t have\u00a0<strong>build-essential<\/strong>\u00a0package installed in your system by default, you can install the latest available version from the default distribution repositories as follows:<\/p>\n<pre># apt-get update &amp;&amp; apt-get install build-essential     \r\nOR\r\n$ sudo get update &amp;&amp; apt-get install build-essential<\/pre>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/01ufcjnxPmE\" width=\"780\" height=\"439\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Now we\u2019re ready to start typing\u00a0<strong>C<\/strong>\u00a0or\u00a0<strong>C++<\/strong>\u00a0code\u2026 or almost. We\u2019re about to show you yet another tool to boost your development toolset.<\/p>\n<h3>Speeding Up C and C++ Compilations<\/h3>\n<p>When you know you\u2019ll need to compile a program, make changes, then recompile again it\u2019s great to have a tool like\u00a0<strong>ccache<\/strong>, which as you will probably guess based on its name, is a compiler cache.<\/p>\n<p>It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Besides\u00a0<strong>C<\/strong>\u00a0and\u00a0<strong>C++<\/strong>, it also supports\u00a0<strong>Objective-C<\/strong>\u00a0and\u00a0<strong>Objective-C++<\/strong>. The only limitations are:<\/p>\n<ol>\n<li>Only supports caching the compilation of a single C\/C++\/Objective-C\/Objective-C++ file. For other types of compilations (multi-file compilation, linking, to name a few examples), the process will end up running the real compiler.<\/li>\n<li>Some compiler flags may not supported. If such a flag is detected, ccache will silently fall back to running the real compiler.<\/li>\n<\/ol>\n<p>Let\u2019s install this tool:<\/p>\n<pre># aptitude install ccache\r\n<\/pre>\n<div id=\"attachment_15929\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-CCache-in-Debian.gif\"><img decoding=\"async\" class=\"size-medium wp-image-15929\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Install-CCache-in-Debian.gif\" alt=\"Install CCache in Debian\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install CCache in Debian<\/p>\n<\/div>\n<p>In the next section we will see some examples of C and C++ code compilation with and without ccache.<\/p>\n<h3>Testing C and C++ with a sample Program<\/h3>\n<p>Let\u2019s use the classical example of a very basic C program that adds two numbers. Open your favorite text editor and enter the following code, then save as\u00a0<code>sum.c<\/code>:<\/p>\n<pre>#include&lt;stdio.h&gt;\r\nint main()\r\n{\r\n   int a, b, c;\r\n   printf(\"Enter two numbers to add, separated by a space: \");\r\n   scanf(\"%d%d\",&amp;a,&amp;b);\r\n   c = a + b;\r\n   printf(\"The sum of equals %d\\n\",c);\r\n   return 0;\r\n}\r\n<\/pre>\n<p>To compile the above code into an executable named sum in the current working directory use the\u00a0<strong>-o<\/strong>\u00a0switch with\u00a0<strong>gcc<\/strong>:<\/p>\n<pre># gcc sum.c -o sum\r\n<\/pre>\n<p>If you want to take advantage of\u00a0<strong>ccache<\/strong>, just prepend the above command with ccache, as follows:<\/p>\n<pre># ccache gcc sum.c -o sum\r\n<\/pre>\n<p>Then run the binary:<\/p>\n<pre># .\/sum\r\n<\/pre>\n<div id=\"attachment_15930\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Compile-C-Program.gif\"><img decoding=\"async\" class=\"size-medium wp-image-15930\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Compile-C-Program.gif\" alt=\"Compile C++ Program in Debian\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Compile C++ Program in Debian<\/p>\n<\/div>\n<p>While this basic example does not allow us to see the full power of ccache, for larger programs you\u2019ll quickly realize what a great tool it is. The same applies for C++ programs as well.<\/p>\n<h3>Summary<\/h3>\n<p>In this guide we have shown how to install and use the GNU compilers for C and C++ in Debian and derivatives. In addition, we explained how to use a compiler cache to speed up recompilations of the same code. While you can refer to the online man pages for gcc and g++ for further options and examples, don\u2019t hesitate to drop us a note using the form below If you have any questions or comments.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-c-compiler-and-development-build-essential-tools-in-debian-ubuntu\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most Linux system administrators and engineers are required to know some basic programming to help them in their daily tasks. If they want to go one step further into the development area as well (either as kernel or application programmers), then\u00a0C\u00a0or\u00a0C++\u00a0is the best place to start. Install C, C++ Compiler and Build Essential Tools Read &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/17\/install-c-c-compiler-and-development-build-essential-tools-in-debian-ubuntu\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Install C, C++ Compiler and Development (build-essential) Tools in Debian\/Ubuntu&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11811","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11811"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11811\/revisions"}],"predecessor-version":[{"id":11812,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11811\/revisions\/11812"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}