{"id":496,"date":"2018-07-16T05:06:53","date_gmt":"2018-07-16T05:06:53","guid":{"rendered":"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=496"},"modified":"2019-05-16T09:37:20","modified_gmt":"2019-05-16T09:37:20","slug":"gnu-compiler-collection","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/chapter\/gnu-compiler-collection\/","title":{"rendered":"GNU Compiler Collection"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/4zwrrvhhwQs\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<ol>\r\n \t<li><strong>Introduction<\/strong><\/li>\r\n<\/ol>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">We know that for achieving desired task from computer, it is required to feed <em>appropriate<\/em> <em>instructions <\/em>to the computer. Such a set of appropriate instructions is known as<em> computer program<\/em>. The act of writing or creating<em> computer program <\/em>is called<em> computer programming<\/em>. However, the computer system being an electronic machine, such instructions a.k.a. computer program must be given in the machine understandable format. Upon assigning the program for execution to the computer system, the processing unit inside the computer understands and executes the program written in machine level language.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Therefore, it designates that the computer programmer (a person who writes computer programs) must know how to write computer program using machine understandable language in order to create successful computer program and thereby get the desired work done from computer. Vice versa, the programmer must be able to read such machine understandable instructions. Gradually the high-level languages evolved for helping programmer community expedite the programming process. Programs written using high-level languages are readable by human.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">However, computers cannot understand the programs written using high-level languages. Hence, some mechanism is required which can transform the programs written in high-level languages to the machine understandable code also known as object code. Programming language experts have successfully built such software programs called <em>compiler<\/em> which can translate the high-level language programs (source code) to the machine understandable object code. <em>Compiler<\/em> is a set of computer programs that generate machine understandable object code from the given source code written in a particular programming language. The compiler software performs additional many important activities also, which are described in upcoming section.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">For example, suppose a programmer has written a computer program using C language to implement simple mathematical calculator. The C program file which is written by the programmer is called source file. In this case, the C source file for the calculator program cannot be directly submitted to CPU for execution as CPU does not understand C language. Hence, next step is to generate machine understandable object code from the C source file using suitable compiler program which knows how to translate C source code into object code. On successful generation of the binary calculator program, it can be submitted to CPU for execution. The same case should be considered for other programming languages such as C++, Java etc.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">An overview of general compilation process is explained in this module. The module explains compilation procedure for C and C++ programs. The module also explained some of the commonly used compilation options with the gcc compiler. How to generate some intermediate files \u2013 is also explained in this module.<\/p>\r\n\r\n<ol start=\"2\">\r\n \t<li><strong> Overview of compilation process<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">Program compilation involves multiple stages. There are four essential phases of compiling a C\/C++ program. Often, the awareness about program compilation process becomes beneficial to programmer in debugging programs and writing efficient programs.<\/p>\r\n&nbsp;\r\n\r\nC\/C++ program compilation involves the following stages (Figure 1):\r\n<ul>\r\n \t<li>Preprocessing<\/li>\r\n \t<li>Compilation<\/li>\r\n \t<li>Assembly<\/li>\r\n \t<li>Linking<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\">Modern compilers coordinate the implicit execution of all four stages mentioned above during program compilation.<\/p>\r\n&nbsp;\r\n\r\nLet us understand purpose of each of the above mentioned compilation stages for the following\r\n\r\n&nbsp;\r\n\r\nC Filename: cprogram.c\r\n\r\n#include &lt;stdio.h&gt;\r\n\r\n&nbsp;\r\n\r\nint main()\r\n\r\n{\r\n\r\nprintf(\u201cDennis Ritchie Sir.\\n\u201d);\r\n\r\nreturn 0;\r\n\r\n}\r\n\r\n&nbsp;\r\n\r\n<strong>Preprocessing<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Before the program gets actually translated to object code, the compilation process invokes preprocessing phase, also called first pass of program compilation. It operates macros, \u201c# include\u201d \u2013 files and conditional compilation for transforming the brief abbreviations into actual C\/C++ - constructs.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-497 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2.jpg\" alt=\"\" width=\"478\" height=\"622\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">For example, all lines starting with the # symbol in the program are processed by the preprocessor software:<\/p>\r\n&nbsp;\r\n\r\n(a) #include &lt;stdio.h&gt;\u00a0 \u00a0 \/\/include header files\r\n\r\n#include &lt;math.h&gt;\r\n\r\n#include &lt;iostream&gt;\r\n\r\n(b) #define SIMPLE_INTEREST_RATE 3.14 \/\/ macro defined #define ARRAY_SIZE 10\r\n\r\n#define PASS_CRITERIA 50\r\n\r\n(c) #ifndef PASS_CRITERIA\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ conditional code group\r\n\r\nprintf(\u201cMinimum percentage required to pass is not defined.\u201d);\r\n\r\n#endif\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The preprocessor software treats the above mentioned lines as preprocessor commands and replaces - the macros (#define), include files (#include) and conditional compilation codes (#ifndef, #ifdef, #endif) - by their respective source codes and values in the program source file. The compiler submits the resultant file to the next compilation phase. Few lines of the output file generated by the preprocessor are shown in Figure 2.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-498 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2.jpg\" alt=\"\" width=\"740\" height=\"357\" \/><\/p>\r\n\r\n<div>\r\n\r\n<strong>Compilation<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">It is second phase of overall compilation process. Also known as a second pass, it is responsible to generate assembler source code if the source file does not contain syntax errors. In this phase, the preprocessed code (previous phase) is transformed into target platform specific human readable assembly-language instructions.<span style=\"text-align: initial; font-size: 1em;\">Output assembly code for our sample program is shown in following Figure 3.<\/span><\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-499 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1.jpg\" alt=\"\" width=\"555\" height=\"548\" \/><\/p>\r\n<strong>Assembly<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the assembly stage, the assembly instructions (generated during compilation stage) are translated into object code i.e. machine code. The assembly language to machine language conversion is done by the \u201eassembler\u201f software named \u201e<em>as\u2019<\/em>. In fact the assembler software is a separate program, but it is internally called automatically during the program compilation process. The resultant file contains the actual executable instructions by the machine.<\/p>\r\n&nbsp;\r\n\r\n<strong>Linking<\/strong>\r\n\r\n&nbsp;\r\n\r\nFinal stage of program compilation is linking. In this phase, a special software known as <em>linker<\/em> links various object files (generated in the assembly stage) to produce a final executable file.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In our example program cprogram.c file, a function printf() is used for printing a message on screen. However, the printf() function is not a user-defined function, it is available in a pre-compiled object file named printf.o. Therefore, it is required to merge the contents of the two object files cprogram.o and printf.o for generating the final executable file cprogram.x, the task is done by the linker software named \u201e<em>ld\u2019<\/em>. Like the assembler software, the linker software <em>ld<\/em> is a separate program, but it is internally called automatically during program compilation process.<\/p>\r\n\r\n<ol start=\"3\">\r\n \t<li><strong>GNU Compiler Collection (GCC)<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">The abbreviation GCC initially stood for \u201cGNU C Compiler\u201d. It was released in 1987 for compiling C programs. It was developed by GNU Project founder Richard Stallman. However, now it officially stands for \u201cGNU Compiler Collection\u201d. The collection offers software for compilation of programs written using various programming languages such as C (gcc), C++ (g++), Objective C (gobjc), Objective C++ (gobjc++), java (gcj), Fortran (gfortran), Ada (gnat), Go (gccgo) and BRIG.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Presently GCC is designed for several types of instruction set architectures (ISAs). Moreover, GCC is official compiler for the UNIX-like GNU operating system and hence it has been adopted as standard compiler by UNIX &amp; LINUX family operating systems. GCC is freely available under the GNU GPL license.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">This module explains how to compile programs written in C &amp; C++ languages using gcc &amp; g++ compilers respectively. In fact, the gcc &amp; g++ compilers are very rich in features. Some of the frequently used features and their usage are explained in this module.<\/p>\r\n\r\n<ol start=\"4\">\r\n \t<li><strong> Installing gcc &amp; g++<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">Use command \u201egcc \u2013-version\u201f to check availability of the gcc compiler in your Linux system. The output shown in following figure 4 you will receive if the gcc compiler is available in your Linux system.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-500 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1.jpg\" alt=\"\" width=\"685\" height=\"130\" \/><\/p>\r\n\r\n<div>\r\n<p style=\"text-align: justify;\">If the gcc compiler is not available in your system, then you will receive an error message: \u201cbash: gcc: command not found\u2026\u201d. In same way the \u201cg++ --version\u201d command may be used to check availability of the g++ compiler.<\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify;\"><strong>\u00a0 \u00a0 Installing gcc &amp; g++ on Fedora\/CentOS systems<\/strong><\/p>\r\n<p style=\"text-align: justify;\">Use following command on Fedora\/CentOS Linux system for installing gcc and g++ compilers:<\/p>\r\n<p style=\"text-align: justify;\">$ sudo yum install gcc gcc-c++<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><strong>Installing gcc &amp; g++ on Ubuntu systems<\/strong><\/p>\r\n<p style=\"text-align: justify;\">Use following command on Ubuntu Linux system for installing gcc and g++ compilers:<\/p>\r\n<p style=\"text-align: justify;\">$ sudo yum apt-get install gcc g++<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><strong>Getting help about gcc<\/strong><\/p>\r\n<p style=\"text-align: justify;\">Moreover, help about gcc can be obtained using \u201egcc --help\u201f command. Use \u201eman gcc\u201f command to access man pages for the gcc compiler.<\/p>\r\n\r\n<ol start=\"5\">\r\n \t<li><strong> Compiling C program using <\/strong><strong>gcc<\/strong><\/li>\r\n<\/ol>\r\nThis section explains how to compile a C program cprogram.c shown in following figure 5.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-501 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1.jpg\" alt=\"\" width=\"530\" height=\"183\" \/><\/p>\r\n<p style=\"text-align: justify;\">The gcc command is used to invoke the GCC C-compiler for compiling C programs. Provide source filename as command line argument to the gcc compiler.<\/p>\r\n&nbsp;\r\n\r\n$ gcc cprogram.c\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">However, notice that the program shown in Figure 5 contains an error on line 5. The statement shown on line 5 should end with the \u201e;\u201f symbol. Hence, running gcc command on the erroneous cprogram.c reports an error message and line number, shown in following Figure 6.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-502 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1.jpg\" alt=\"\" width=\"488\" height=\"94\" \/><\/p>\r\n<p style=\"text-align: justify;\">On successful compilation, gcc generates the executable file a.out. Execution output is shown in figure 7.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-503 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A7.jpg\" alt=\"\" width=\"491\" height=\"136\" \/><\/p>\r\n<p style=\"text-align: justify;\">On successful compilation, gcc assigns a default name \u201ea.out\u201f to the resultant binary executable file. However, programmer may create the binary executable having file name of his choice. Use \u2013o option and supply the desired file name for the resulting binary executable. In the example shown in figure 8, the gcc compiles source file cprogram.c to machine executable object code and stores it in executable file cprogram.exe.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-504 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A8.jpg\" alt=\"\" width=\"552\" height=\"114\" \/><\/p>\r\n\r\n<div>\r\n\r\n<strong>Compiling C++ program using <\/strong><strong>g++<\/strong>\r\n\r\n&nbsp;\r\n\r\nUse g++ command to compile C++ programs. Consider following cppprogram.cc:\r\n\r\nFile: cppprogram.cc\r\n\r\nusing namespace std;\r\n\r\n#include&lt;isotream&gt;\r\n\r\nint main()\r\n\r\n{\r\n\r\ncout&lt;&lt;\u201dThis is C++ program.\u201d&lt;&lt;endl; return 0;\r\n\r\n}\r\n\r\n<\/div>\r\n<p style=\"text-align: center;\">The above mentioned C++ program compilation using g++ command and execution is shown in following figure 9.<img class=\"size-full wp-image-506 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111.jpg\" alt=\"\" width=\"572\" height=\"90\" \/><\/p>\r\n\r\n<ol start=\"6\">\r\n \t<li><strong> Printing warning messages<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">While compiling the source file, gcc sometimes produces certain warning messages for the programmer. Aim behind producing such warning messages is to make aware the programmer about certain compile-time messages which may be helpful in detecting various logical mistakes and common errors in technically correct programs. The \u2013Wall option enables displaying warnings for several common errors. Let us understand significance of the the \u2013Wall option using the following example.<\/p>\r\n&nbsp;\r\n\r\nfile: warning.c\r\n\r\n#include&lt;stdio.h&gt;\r\n\r\nint main()\r\n\r\n{\r\n\r\nfloat simple_interest_rate;\r\n\r\nprintf(\u201cBank Simple interest rate is: %f\\n\u201d, simple_interest_rate);\r\n\r\nreturn 0;\r\n\r\n}\r\n<p style=\"text-align: justify;\">Compiling with \u2013Wall option gcc not only generates the executable file but also notifies some warning message on screen. The warning message suggests that the variable simple_interest_rate is used without initialization (Figure 10). However, the resultant executable file with_warning.exe is successfully generated. Execution output is shown in figure 10.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-507 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111.jpg\" alt=\"\" width=\"769\" height=\"128\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In figure 10, it is seen that the binary executable is generated even though the compiler has raised compile-time warning. However, if the programmer desires, he may instruct the gcc to not to generate executable file in case of compile-time warnings. The \u2013Werror option is used with the<\/p>\r\n\u2013Wall option (figure 11).\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-508 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333.jpg\" alt=\"\" width=\"776\" height=\"145\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Create preprocessor output only<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Preprocessing is first inherent stage in the overall compilation process. It is possible to produce the preprocessor output only for a given C source file using \u2013E option with gcc. By default it generates the preprocessor output on screen, which can be redirected to some output file using redirection operator &gt;.<\/p>\r\n$ gcc \u2013E cprogram.c &gt; cprogram.i\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The resultant preprocessor output file cprogram.i contains human-readable contents. Use any text editor or cat command to view contents of the file. Contents of the cprogram.i file is shown in figure 2.<\/p>\r\n&nbsp;\r\n\r\n<strong>Create assembly code only<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">After successful completion of preprocessor stage, the source code is translated to machine-specific assembly language. The gcc compiler also provides an option to produce the assembly code only for a given C source file using \u2013S option.<\/p>\r\n&nbsp;\r\n\r\n$ gcc \u2013S cprogram.c\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The resultant human-readable file cprogram.s contains machine-specific assembly code. Use any text editor or cat command to view contents of the file. Contents of the cprogram.s file is shown in figure 3.<\/p>\r\n&nbsp;\r\n\r\n<strong>Create compiled code only (without linking)<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">After successful generation of the assembly code, gcc translates (compiles) the assembly code to object code. Use \u2013C option to generate the compiled code only without linking the object file to other library files.<\/p>\r\n&nbsp;\r\n\r\n$ gcc \u2013C cprogram.c\r\n\r\n&nbsp;\r\n\r\n<span style=\"text-align: initial; font-size: 1em;\">The \u2013C option with the gcc command will create the machine-specific object code in cprogram.o output file.<\/span>\r\n\r\n<\/div>\r\n<strong>Generate all intermediate files<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">It is also possible to generate all intermediate files using \u2013save-temps option. The output shown in figure 12 is self-explanatory.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-509 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444.jpg\" alt=\"\" width=\"716\" height=\"164\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Treat char datatype as unsigned char datatype<\/strong>\r\n\r\n&nbsp;\r\n\r\nBeing\u00a0 ANSI\u00a0 compliant\u00a0 compiler,\u00a0 the\u00a0 gcc\u00a0\u00a0\u00a0 supports\u00a0 signed\u00a0 and\u00a0\u00a0 unsigned\u00a0\u00a0 char\u00a0\u00a0\u00a0 datatypes.\r\n<p style=\"text-align: justify;\">However if required, the programmer may instruct gcc to forcefully interpret the char type as unsigned char type. Use the \u2013funsigned-char option with the command gcc to interpret char type as unsigned char. In following example, a negative value is assigned to the<\/p>\r\n&nbsp;\r\n\r\nsomechar variable of type char.\r\n\r\nFile: unsigned.c\r\n\r\n#include&lt;stdio.h&gt;\r\n\r\nint main()\r\n\r\n{\r\n\r\nchar somechar = -65; printf(\u201csomechar = %d\\n\u201d,somechar);\r\n\r\nreturn 0;\r\n\r\n}\r\n<p style=\"text-align: justify;\">Compiling the program unsigned.c shown above without using the \u2013funsigned-char option results into the output shown figure 13.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-510 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111.jpg\" alt=\"\" width=\"583\" height=\"94\" \/><\/p>\r\n<p style=\"text-align: center;\">However, in presence of the \u2013funsigned-char option, results into different behavior by gcc, shown in figure 14.<img class=\"size-full wp-image-511 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1.jpg\" alt=\"\" width=\"726\" height=\"76\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Contrary to the \u2013funsigned-char option, there exists a \u2013fsigned-char option, it is used to instruct gcc to interpret the char type as signed char type.<\/p>\r\n&nbsp;\r\n\r\n<strong>Compile-time macros<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The gcc compiler supports compile-time macros. It is possible to supply the compile-time macros on gcc command-line using \u2013D&lt;macro-name&gt; option. Following example, expects availability of macro MY_MACRO.<\/p>\r\n&nbsp;\r\n\r\nFile: macros.c\r\n\r\n#include&lt;stdio.h&gt;\r\n\r\nint main()\r\n\r\n{\r\n\r\n#ifdef MY_MACRO\r\n\r\nprintf(\u201cMY_MACRO is defined.\\n\u201d);\r\n\r\n#else\r\n\r\nprintf(\u201cMY_MACRO is not defined.\\n\u201d);\r\n\r\n#endif\r\n\r\n}\r\n<p style=\"text-align: justify;\">Execution behavior of the compiled program macros.c in presence and absence of the option \u2013DMY_MACRO is shown in figure 15 &amp; figure 16 respectively.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-512 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3.jpg\" alt=\"\" width=\"645\" height=\"76\" \/><\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-513 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4.jpg\" alt=\"\" width=\"548\" height=\"75\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Supply path for <\/strong><strong>include<\/strong><strong> directory<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe gcc compiler provides \u2013I&lt;path-to-headers&gt; to supply the <strong>include<\/strong> directory-path on gcc command line:\r\n\r\n$ gcc \u2013Wall \u2013I\/home\/joshi\/cprograms\/include cprogram.c\r\n\r\n&nbsp;\r\n\r\n<strong>Link with library<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Use the \u2013l&lt;library-name&gt; to link your program with a library file. For example, the following command links the aprogram.c program file to the math library.<\/p>\r\n&nbsp;\r\n\r\n$ gcc \u2013Wall aprogram.c \u2013lmath \u2013o aprogram.exe\r\n\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Program compilation is required to transform the human-readable source code to machine executable code. The task of program source code compilation inherently coordinates various stages such as preprocessing, compilation, assembly and linking. Nowadays, several compilation software exist.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The GCC (GNU Compiler Collection) suite consists of compilation software such as gcc, g++, gobjc, gobjc++, gcj, gfortran, gnat and gccgo for programs written in various programming languages such as C, C++, Objective C, Objective C++, java, Fortran, Ada and Go respectively. GCC is freely available under the GNU GPL license.<\/p>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on GNU Compiler Collection<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/4zwrrvhhwQs\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<strong>References and Further Reading<\/strong>\r\n<ol>\r\n \t<li style=\"text-align: justify;\">Programming with GNU Software, Mike Loukides, O\u2019Reilly Publication<\/li>\r\n \t<li style=\"text-align: justify;\">An Introduction to GCC, Brian Gough, Network Theory Limited<\/li>\r\n \t<li style=\"text-align: justify;\">The Definitive Guide to GCC, William von Hagen, Apress<\/li>\r\n \t<li style=\"text-align: justify;\">Using the GNU Compiler Collection (GCC), Richard M. Stallman and GCC Developer Community, Weblink: https:\/\/gcc.gnu.org\/onlinedocs\/gcc-4.1.2\/gcc.pdf<\/li>\r\n<\/ol>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/4zwrrvhhwQs\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<ol>\n<li><strong>Introduction<\/strong><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">We know that for achieving desired task from computer, it is required to feed <em>appropriate<\/em> <em>instructions <\/em>to the computer. Such a set of appropriate instructions is known as<em> computer program<\/em>. The act of writing or creating<em> computer program <\/em>is called<em> computer programming<\/em>. However, the computer system being an electronic machine, such instructions a.k.a. computer program must be given in the machine understandable format. Upon assigning the program for execution to the computer system, the processing unit inside the computer understands and executes the program written in machine level language.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Therefore, it designates that the computer programmer (a person who writes computer programs) must know how to write computer program using machine understandable language in order to create successful computer program and thereby get the desired work done from computer. Vice versa, the programmer must be able to read such machine understandable instructions. Gradually the high-level languages evolved for helping programmer community expedite the programming process. Programs written using high-level languages are readable by human.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">However, computers cannot understand the programs written using high-level languages. Hence, some mechanism is required which can transform the programs written in high-level languages to the machine understandable code also known as object code. Programming language experts have successfully built such software programs called <em>compiler<\/em> which can translate the high-level language programs (source code) to the machine understandable object code. <em>Compiler<\/em> is a set of computer programs that generate machine understandable object code from the given source code written in a particular programming language. The compiler software performs additional many important activities also, which are described in upcoming section.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">For example, suppose a programmer has written a computer program using C language to implement simple mathematical calculator. The C program file which is written by the programmer is called source file. In this case, the C source file for the calculator program cannot be directly submitted to CPU for execution as CPU does not understand C language. Hence, next step is to generate machine understandable object code from the C source file using suitable compiler program which knows how to translate C source code into object code. On successful generation of the binary calculator program, it can be submitted to CPU for execution. The same case should be considered for other programming languages such as C++, Java etc.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">An overview of general compilation process is explained in this module. The module explains compilation procedure for C and C++ programs. The module also explained some of the commonly used compilation options with the gcc compiler. How to generate some intermediate files \u2013 is also explained in this module.<\/p>\n<ol start=\"2\">\n<li><strong> Overview of compilation process<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Program compilation involves multiple stages. There are four essential phases of compiling a C\/C++ program. Often, the awareness about program compilation process becomes beneficial to programmer in debugging programs and writing efficient programs.<\/p>\n<p>&nbsp;<\/p>\n<p>C\/C++ program compilation involves the following stages (Figure 1):<\/p>\n<ul>\n<li>Preprocessing<\/li>\n<li>Compilation<\/li>\n<li>Assembly<\/li>\n<li>Linking<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Modern compilers coordinate the implicit execution of all four stages mentioned above during program compilation.<\/p>\n<p>&nbsp;<\/p>\n<p>Let us understand purpose of each of the above mentioned compilation stages for the following<\/p>\n<p>&nbsp;<\/p>\n<p>C Filename: cprogram.c<\/p>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>int main()<\/p>\n<p>{<\/p>\n<p>printf(\u201cDennis Ritchie Sir.\\n\u201d);<\/p>\n<p>return 0;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Preprocessing<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Before the program gets actually translated to object code, the compilation process invokes preprocessing phase, also called first pass of program compilation. It operates macros, \u201c# include\u201d \u2013 files and conditional compilation for transforming the brief abbreviations into actual C\/C++ &#8211; constructs.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-497 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2.jpg\" alt=\"\" width=\"478\" height=\"622\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2.jpg 478w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2-231x300.jpg 231w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2-65x85.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2-225x293.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-2-350x455.jpg 350w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">For example, all lines starting with the # symbol in the program are processed by the preprocessor software:<\/p>\n<p>&nbsp;<\/p>\n<p>(a) #include &lt;stdio.h&gt;\u00a0 \u00a0 \/\/include header files<\/p>\n<p>#include &lt;math.h&gt;<\/p>\n<p>#include &lt;iostream&gt;<\/p>\n<p>(b) #define SIMPLE_INTEREST_RATE 3.14 \/\/ macro defined #define ARRAY_SIZE 10<\/p>\n<p>#define PASS_CRITERIA 50<\/p>\n<p>(c) #ifndef PASS_CRITERIA\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ conditional code group<\/p>\n<p>printf(\u201cMinimum percentage required to pass is not defined.\u201d);<\/p>\n<p>#endif<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The preprocessor software treats the above mentioned lines as preprocessor commands and replaces &#8211; the macros (#define), include files (#include) and conditional compilation codes (#ifndef, #ifdef, #endif) &#8211; by their respective source codes and values in the program source file. The compiler submits the resultant file to the next compilation phase. Few lines of the output file generated by the preprocessor are shown in Figure 2.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-498 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2.jpg\" alt=\"\" width=\"740\" height=\"357\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2.jpg 740w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2-300x145.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2-65x31.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2-225x109.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A2-2-350x169.jpg 350w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<div>\n<p><strong>Compilation<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">It is second phase of overall compilation process. Also known as a second pass, it is responsible to generate assembler source code if the source file does not contain syntax errors. In this phase, the preprocessed code (previous phase) is transformed into target platform specific human readable assembly-language instructions.<span style=\"text-align: initial; font-size: 1em;\">Output assembly code for our sample program is shown in following Figure 3.<\/span><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-499 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1.jpg\" alt=\"\" width=\"555\" height=\"548\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1.jpg 555w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1-300x296.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1-65x64.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1-225x222.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-1-350x346.jpg 350w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\n<p><strong>Assembly<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the assembly stage, the assembly instructions (generated during compilation stage) are translated into object code i.e. machine code. The assembly language to machine language conversion is done by the \u201eassembler\u201f software named \u201e<em>as\u2019<\/em>. In fact the assembler software is a separate program, but it is internally called automatically during the program compilation process. The resultant file contains the actual executable instructions by the machine.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Linking<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Final stage of program compilation is linking. In this phase, a special software known as <em>linker<\/em> links various object files (generated in the assembly stage) to produce a final executable file.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In our example program cprogram.c file, a function printf() is used for printing a message on screen. However, the printf() function is not a user-defined function, it is available in a pre-compiled object file named printf.o. Therefore, it is required to merge the contents of the two object files cprogram.o and printf.o for generating the final executable file cprogram.x, the task is done by the linker software named \u201e<em>ld\u2019<\/em>. Like the assembler software, the linker software <em>ld<\/em> is a separate program, but it is internally called automatically during program compilation process.<\/p>\n<ol start=\"3\">\n<li><strong>GNU Compiler Collection (GCC)<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">The abbreviation GCC initially stood for \u201cGNU C Compiler\u201d. It was released in 1987 for compiling C programs. It was developed by GNU Project founder Richard Stallman. However, now it officially stands for \u201cGNU Compiler Collection\u201d. The collection offers software for compilation of programs written using various programming languages such as C (gcc), C++ (g++), Objective C (gobjc), Objective C++ (gobjc++), java (gcj), Fortran (gfortran), Ada (gnat), Go (gccgo) and BRIG.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Presently GCC is designed for several types of instruction set architectures (ISAs). Moreover, GCC is official compiler for the UNIX-like GNU operating system and hence it has been adopted as standard compiler by UNIX &amp; LINUX family operating systems. GCC is freely available under the GNU GPL license.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">This module explains how to compile programs written in C &amp; C++ languages using gcc &amp; g++ compilers respectively. In fact, the gcc &amp; g++ compilers are very rich in features. Some of the frequently used features and their usage are explained in this module.<\/p>\n<ol start=\"4\">\n<li><strong> Installing gcc &amp; g++<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Use command \u201egcc \u2013-version\u201f to check availability of the gcc compiler in your Linux system. The output shown in following figure 4 you will receive if the gcc compiler is available in your Linux system.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-500 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1.jpg\" alt=\"\" width=\"685\" height=\"130\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1.jpg 685w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1-300x57.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1-65x12.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1-225x43.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-1-350x66.jpg 350w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/p>\n<div>\n<p style=\"text-align: justify;\">If the gcc compiler is not available in your system, then you will receive an error message: \u201cbash: gcc: command not found\u2026\u201d. In same way the \u201cg++ &#8211;version\u201d command may be used to check availability of the g++ compiler.<\/p>\n<\/div>\n<p style=\"text-align: justify;\"><strong>\u00a0 \u00a0 Installing gcc &amp; g++ on Fedora\/CentOS systems<\/strong><\/p>\n<p style=\"text-align: justify;\">Use following command on Fedora\/CentOS Linux system for installing gcc and g++ compilers:<\/p>\n<p style=\"text-align: justify;\">$ sudo yum install gcc gcc-c++<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><strong>Installing gcc &amp; g++ on Ubuntu systems<\/strong><\/p>\n<p style=\"text-align: justify;\">Use following command on Ubuntu Linux system for installing gcc and g++ compilers:<\/p>\n<p style=\"text-align: justify;\">$ sudo yum apt-get install gcc g++<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><strong>Getting help about gcc<\/strong><\/p>\n<p style=\"text-align: justify;\">Moreover, help about gcc can be obtained using \u201egcc &#8211;help\u201f command. Use \u201eman gcc\u201f command to access man pages for the gcc compiler.<\/p>\n<ol start=\"5\">\n<li><strong> Compiling C program using <\/strong><strong>gcc<\/strong><\/li>\n<\/ol>\n<p>This section explains how to compile a C program cprogram.c shown in following figure 5.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-501 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1.jpg\" alt=\"\" width=\"530\" height=\"183\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1.jpg 530w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1-300x104.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1-65x22.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1-225x78.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-1-350x121.jpg 350w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/><\/p>\n<p style=\"text-align: justify;\">The gcc command is used to invoke the GCC C-compiler for compiling C programs. Provide source filename as command line argument to the gcc compiler.<\/p>\n<p>&nbsp;<\/p>\n<p>$ gcc cprogram.c<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">However, notice that the program shown in Figure 5 contains an error on line 5. The statement shown on line 5 should end with the \u201e;\u201f symbol. Hence, running gcc command on the erroneous cprogram.c reports an error message and line number, shown in following Figure 6.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-502 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1.jpg\" alt=\"\" width=\"488\" height=\"94\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1.jpg 488w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1-300x58.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1-65x13.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1-225x43.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-1-350x67.jpg 350w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/p>\n<p style=\"text-align: justify;\">On successful compilation, gcc generates the executable file a.out. Execution output is shown in figure 7.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-503 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A7.jpg\" alt=\"\" width=\"491\" height=\"136\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7.jpg 491w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-300x83.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-65x18.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-225x62.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-350x97.jpg 350w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/p>\n<p style=\"text-align: justify;\">On successful compilation, gcc assigns a default name \u201ea.out\u201f to the resultant binary executable file. However, programmer may create the binary executable having file name of his choice. Use \u2013o option and supply the desired file name for the resulting binary executable. In the example shown in figure 8, the gcc compiles source file cprogram.c to machine executable object code and stores it in executable file cprogram.exe.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-504 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A8.jpg\" alt=\"\" width=\"552\" height=\"114\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8.jpg 552w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-300x62.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-65x13.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-225x46.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-350x72.jpg 350w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/p>\n<div>\n<p><strong>Compiling C++ program using <\/strong><strong>g++<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Use g++ command to compile C++ programs. Consider following cppprogram.cc:<\/p>\n<p>File: cppprogram.cc<\/p>\n<p>using namespace std;<\/p>\n<p>#include&lt;isotream&gt;<\/p>\n<p>int main()<\/p>\n<p>{<\/p>\n<p>cout&lt;&lt;\u201dThis is C++ program.\u201d&lt;&lt;endl; return 0;<\/p>\n<p>}<\/p>\n<\/div>\n<p style=\"text-align: center;\">The above mentioned C++ program compilation using g++ command and execution is shown in following figure 9.<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-506 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111.jpg\" alt=\"\" width=\"572\" height=\"90\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111.jpg 572w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111-300x47.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111-65x10.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111-225x35.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1111-350x55.jpg 350w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/p>\n<ol start=\"6\">\n<li><strong> Printing warning messages<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">While compiling the source file, gcc sometimes produces certain warning messages for the programmer. Aim behind producing such warning messages is to make aware the programmer about certain compile-time messages which may be helpful in detecting various logical mistakes and common errors in technically correct programs. The \u2013Wall option enables displaying warnings for several common errors. Let us understand significance of the the \u2013Wall option using the following example.<\/p>\n<p>&nbsp;<\/p>\n<p>file: warning.c<\/p>\n<p>#include&lt;stdio.h&gt;<\/p>\n<p>int main()<\/p>\n<p>{<\/p>\n<p>float simple_interest_rate;<\/p>\n<p>printf(\u201cBank Simple interest rate is: %f\\n\u201d, simple_interest_rate);<\/p>\n<p>return 0;<\/p>\n<p>}<\/p>\n<p style=\"text-align: justify;\">Compiling with \u2013Wall option gcc not only generates the executable file but also notifies some warning message on screen. The warning message suggests that the variable simple_interest_rate is used without initialization (Figure 10). However, the resultant executable file with_warning.exe is successfully generated. Execution output is shown in figure 10.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-507 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111.jpg\" alt=\"\" width=\"769\" height=\"128\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111.jpg 769w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111-300x50.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111-768x128.jpg 768w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111-65x11.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111-225x37.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A111111111111111111111-350x58.jpg 350w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In figure 10, it is seen that the binary executable is generated even though the compiler has raised compile-time warning. However, if the programmer desires, he may instruct the gcc to not to generate executable file in case of compile-time warnings. The \u2013Werror option is used with the<\/p>\n<p>\u2013Wall option (figure 11).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-508 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333.jpg\" alt=\"\" width=\"776\" height=\"145\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333.jpg 776w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333-300x56.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333-768x144.jpg 768w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333-65x12.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333-225x42.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A33333-350x65.jpg 350w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Create preprocessor output only<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Preprocessing is first inherent stage in the overall compilation process. It is possible to produce the preprocessor output only for a given C source file using \u2013E option with gcc. By default it generates the preprocessor output on screen, which can be redirected to some output file using redirection operator &gt;.<\/p>\n<p>$ gcc \u2013E cprogram.c &gt; cprogram.i<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The resultant preprocessor output file cprogram.i contains human-readable contents. Use any text editor or cat command to view contents of the file. Contents of the cprogram.i file is shown in figure 2.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Create assembly code only<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">After successful completion of preprocessor stage, the source code is translated to machine-specific assembly language. The gcc compiler also provides an option to produce the assembly code only for a given C source file using \u2013S option.<\/p>\n<p>&nbsp;<\/p>\n<p>$ gcc \u2013S cprogram.c<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The resultant human-readable file cprogram.s contains machine-specific assembly code. Use any text editor or cat command to view contents of the file. Contents of the cprogram.s file is shown in figure 3.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Create compiled code only (without linking)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">After successful generation of the assembly code, gcc translates (compiles) the assembly code to object code. Use \u2013C option to generate the compiled code only without linking the object file to other library files.<\/p>\n<p>&nbsp;<\/p>\n<p>$ gcc \u2013C cprogram.c<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: initial; font-size: 1em;\">The \u2013C option with the gcc command will create the machine-specific object code in cprogram.o output file.<\/span><\/p>\n<\/div>\n<p><strong>Generate all intermediate files<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">It is also possible to generate all intermediate files using \u2013save-temps option. The output shown in figure 12 is self-explanatory.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-509 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444.jpg\" alt=\"\" width=\"716\" height=\"164\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444.jpg 716w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444-300x69.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444-65x15.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444-225x52.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A44444444444-350x80.jpg 350w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Treat char datatype as unsigned char datatype<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Being\u00a0 ANSI\u00a0 compliant\u00a0 compiler,\u00a0 the\u00a0 gcc\u00a0\u00a0\u00a0 supports\u00a0 signed\u00a0 and\u00a0\u00a0 unsigned\u00a0\u00a0 char\u00a0\u00a0\u00a0 datatypes.<\/p>\n<p style=\"text-align: justify;\">However if required, the programmer may instruct gcc to forcefully interpret the char type as unsigned char type. Use the \u2013funsigned-char option with the command gcc to interpret char type as unsigned char. In following example, a negative value is assigned to the<\/p>\n<p>&nbsp;<\/p>\n<p>somechar variable of type char.<\/p>\n<p>File: unsigned.c<\/p>\n<p>#include&lt;stdio.h&gt;<\/p>\n<p>int main()<\/p>\n<p>{<\/p>\n<p>char somechar = -65; printf(\u201csomechar = %d\\n\u201d,somechar);<\/p>\n<p>return 0;<\/p>\n<p>}<\/p>\n<p style=\"text-align: justify;\">Compiling the program unsigned.c shown above without using the \u2013funsigned-char option results into the output shown figure 13.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-510 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111.jpg\" alt=\"\" width=\"583\" height=\"94\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111.jpg 583w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111-300x48.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111-65x10.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111-225x36.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z111111111111111111111111111111111111111111111111111111111111111111111-350x56.jpg 350w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/p>\n<p style=\"text-align: center;\">However, in presence of the \u2013funsigned-char option, results into different behavior by gcc, shown in figure 14.<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-511 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1.jpg\" alt=\"\" width=\"726\" height=\"76\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1.jpg 726w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1-300x31.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1-65x7.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1-225x24.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z2-1-350x37.jpg 350w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Contrary to the \u2013funsigned-char option, there exists a \u2013fsigned-char option, it is used to instruct gcc to interpret the char type as signed char type.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Compile-time macros<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The gcc compiler supports compile-time macros. It is possible to supply the compile-time macros on gcc command-line using \u2013D&lt;macro-name&gt; option. Following example, expects availability of macro MY_MACRO.<\/p>\n<p>&nbsp;<\/p>\n<p>File: macros.c<\/p>\n<p>#include&lt;stdio.h&gt;<\/p>\n<p>int main()<\/p>\n<p>{<\/p>\n<p>#ifdef MY_MACRO<\/p>\n<p>printf(\u201cMY_MACRO is defined.\\n\u201d);<\/p>\n<p>#else<\/p>\n<p>printf(\u201cMY_MACRO is not defined.\\n\u201d);<\/p>\n<p>#endif<\/p>\n<p>}<\/p>\n<p style=\"text-align: justify;\">Execution behavior of the compiled program macros.c in presence and absence of the option \u2013DMY_MACRO is shown in figure 15 &amp; figure 16 respectively.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-512 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3.jpg\" alt=\"\" width=\"645\" height=\"76\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3.jpg 645w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3-300x35.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3-65x8.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3-225x27.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z3-350x41.jpg 350w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-513 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4.jpg\" alt=\"\" width=\"548\" height=\"75\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4.jpg 548w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4-300x41.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4-65x9.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4-225x31.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/Z4-350x48.jpg 350w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Supply path for <\/strong><strong>include<\/strong><strong> directory<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The gcc compiler provides \u2013I&lt;path-to-headers&gt; to supply the <strong>include<\/strong> directory-path on gcc command line:<\/p>\n<p>$ gcc \u2013Wall \u2013I\/home\/joshi\/cprograms\/include cprogram.c<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Link with library<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Use the \u2013l&lt;library-name&gt; to link your program with a library file. For example, the following command links the aprogram.c program file to the math library.<\/p>\n<p>&nbsp;<\/p>\n<p>$ gcc \u2013Wall aprogram.c \u2013lmath \u2013o aprogram.exe<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Program compilation is required to transform the human-readable source code to machine executable code. The task of program source code compilation inherently coordinates various stages such as preprocessing, compilation, assembly and linking. Nowadays, several compilation software exist.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The GCC (GNU Compiler Collection) suite consists of compilation software such as gcc, g++, gobjc, gobjc++, gcj, gfortran, gnat and gccgo for programs written in various programming languages such as C, C++, Objective C, Objective C++, java, Fortran, Ada and Go respectively. GCC is freely available under the GNU GPL license.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on GNU Compiler Collection<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/4zwrrvhhwQs\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>References and Further Reading<\/strong><\/p>\n<ol>\n<li style=\"text-align: justify;\">Programming with GNU Software, Mike Loukides, O\u2019Reilly Publication<\/li>\n<li style=\"text-align: justify;\">An Introduction to GCC, Brian Gough, Network Theory Limited<\/li>\n<li style=\"text-align: justify;\">The Definitive Guide to GCC, William von Hagen, Apress<\/li>\n<li style=\"text-align: justify;\">Using the GNU Compiler Collection (GCC), Richard M. Stallman and GCC Developer Community, Weblink: https:\/\/gcc.gnu.org\/onlinedocs\/gcc-4.1.2\/gcc.pdf<\/li>\n<\/ol>\n","protected":false},"author":4,"menu_order":34,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-narayan-joshi"],"pb_section_license":""},"chapter-type":[],"contributor":[60],"license":[],"class_list":["post-496","chapter","type-chapter","status-publish","hentry","contributor-dr-narayan-joshi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":7,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/496\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/496\/revisions\/727"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/496\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapter-type?post=496"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/contributor?post=496"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/license?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}