How to Install Gcc in Redhat Linux 6
| ||||
Chapter 4. Compiling and BuildingRed Hat Enterprise Linux 6 includes many packages used for software development, inluding tools for compiling and building source code. This chapter discusses several of these packages and tools used to compile source code.
4.1. GNU Compiler Collection (GCC)The GNU Compiler Collection (GCC) is a set of tools for compiling a variety of programming languages (including C, C++, ObjectiveC,ObjectiveC++, Fortran, and Ada) into highly optimized machine code. These tools include various compilers (like
4.1.1. GCC Status and FeaturesGCC for Red Hat Enterprise Linux 6 is based on the 4.4.x release series and includes several bug fixes, enhancements, and backports from upcoming releases (including the GCC 4.5). However, GCC 4.5 was not considered sufficiently mature for an enterprise distribution when RHEL6 features were frozen. This standardization means that as updates to the 4.4 series become available (4.4.1, 4.4.2, ect), they will be incorporated into the compiler included with RHEL6 as updates. Red Hat may import additional backports and enhancements from upcoming releases outside the 4.4 series that won't break compatibility within the Enterprise Linux release. Occassionally, code that was not compliant to standards may fail to compile or its functionality may change in the process of fixing bugs or maintaining standards compliant behavior. Since the previous release of Red Hat Enterprise Linux, GCC has had three major releases: 4.2.x, 4.3.x, and 4.4.x. A selective summary of the expansive list of changes follows.
For a more detailed list of improvements in GCC, refer to: In addition to the changes introduced via the GCC 4.4 rebase, the Red Hat Enterprise Linux 6 version of GCC also features several fixes and enhancements backported from upstream sources (i.e. version 4.5 and beyond). These improvements include the following (among others):
4.1.2. Language CompatibilityApplication Binary Interfaces specified by the GNU C, C++, Fortran and Java Compiler include:
The default system C compiler included with Red Hat Enterprise Linux 6 is largely compatible with the C99 ABI standard. Deviations from the C99 standard in GCC 4.4 are tracked online. In addition to the C ABI, the Application Binary Interface for the GNU C++ Compiler specifies the binary interfaces needed to support the C++ language, such as:
The default system C++ compiler included with Red Hat Enterprise Linux 6 conforms to the C++ ABI defined by the Itanium C++ ABI (1.86). Although every effort has been made to keep each version of GCC compatibile with previous releases, some incompatibilities do exist. ABI incompatibilities between RHEL6 and RHEL5The following is a list of known incompatibilities between the Red Hat Enterprise Linux 6 and 5 toolchains.
ABI incompatibilities between RHEL5 and RHEL4The following is a list of known incompatibilities between the Red Hat Enterprise Linux 5 and 4 toolchains.
The compiler flag Excluding the incompatibilities listed above, the GCC C and C++ language ABIs are mostly ABI compatible. The vast majority of source code will not encounter any of the known issues, and can be considered compatible. Compatible ABIs allow the objects created by compiling source code to be portable to other systems. In particular, for Red Hat Enterprise Linux, this allows for upward compatibility. Upward compatibility is defined as the ability to link shared libraries and objects, created using a version of the compilers in a particular RHEL release, with no problems. This includes new objects compiled on subsequent RHEL releases. The C ABI is considered to be stable, and has been so since at least RHEL3 (again, barring any incompatibilities mentioned in the above lists). Libraries built on RHEL3 and later can be linked to objects created on a subsequent environment (RHEL4, RHEL5, and RHEL6). The C++ ABI is considered to be stable, but less stable than the C ABI, and only as of RHEL4 (corresponding to GCC version 3.4 and above.). As with C, this is only an upward compatibility. Libraries built on RHEL4 and above can be linked to objects created on a subsequent environment (RHEL5, and RHEL6). To force GCC to generate code compatible with the C++ ABI in RHEL releases prior to RHEL4, some developers have used the The above incompatibilities make it incredibly difficult to maintain ABI shared library sanity between releases, especially if when developing custom libraries with multiple dependencies outside of the core libraries. Therefore, if shared libraries are developed, it is highly recommend that a new version is built for each Red Hat Enterprise Linux release.
4.1.3. Object Compatibility and InteroperabilityTwo items that are important are the changes and enhancements in the underlying tools used by the compiler, and the compatibility between the different versions of a language's compiler. Changes and new features in tools like
Object file changes, such as the ones listed above, may interfere with the portable use of
4.1.4. Backwards Compatibility PackagesSeveral packages are provided to serve as an aid for those moving source code or executables from older versions of Red Hat Enterprise Linux to the current release. These packages are intended to be used as a temporary aid in transitioning sources to newer compilers with changed behavior, or as a convenient way to otherwise isolate differences in the system environment from the compile environment. Please be advised that Red Hat may remove these packages in future Red Hat Enterprise Linux releases. The following packages provide compatibility tools for compiling Fortran or C++ source code on the current release of Red Hat Enterprise Linux 6 as if one was using the older compilers on Red Hat Enterprise Linux 4 :
The following package provides a compatibility runtime library for Fortran exectuables compiled on Red Hat Enterprise Linux 5 to run without recompilation on the current release of Red Hat Enterprise Linux 6:
Please note that backwards compatibility library packages are not provided for all supported system libraries, just the system libraries pertaining to the compiler and the C/C++ standard libraries. For more information about backwards compatibility library packages, refer to the Application Compatibility section of the Red Hat Enterprise Linux 6 Migration Guide.
4.1.5. Previewing RHEL6 compiler features on RHEL5On Red Hat Enterprise Linux 5, we have included the package The RHEL5
4.1.6. Running GCCTo compile using GCC tools, first install In brief, the tools work via the The compiler functions provided by GCC are also integrated into the Eclipse IDE as part of the Conversely, using GCC tools from the command-line interface consumes less system resources. This also allows finer-grained control over compilers; GCC's command-line tools can even be used outside of the graphical mode (runlevel 5).
4.1.6.1. Simple C UsageBasic compilation of a C language program using GCC is easy. Start with the following simple program: hello.c#include <stdio.h> int main () { printf ("Hello world!\n"); return 0; } The following procedure illustrates the compilation process for C in its most basic form. Procedure 4.1. Compiling a 'Hello World' C Program
4.1.6.2. Simple C++ UsageBasic compilation of a C++ language program using GCC is similar. Start with the following simple program: hello.cc#include <iostream> using namespace std; int main(void) { cout << "Hello World!" << endl; return 0; } The following procedure illustrates the compilation process for C++ in its most basic form. Procedure 4.2. Compiling a 'Hello World' C++ Program
4.1.6.3. Simple Multi-File UsageTo use basic compilation involving multiple files or object files, start with the following two source files: one.c#include <stdio.h> void hello() { printf("Hello world!\n"); } two.cextern void hello(); int main() { hello(); return 0; } The following procedure illustrates a simple, multi-file compilation process in its most basic form. Procedure 4.3. Compiling a Program with Muiltiple Source Files
4.1.6.4. Recommended Optimization OptionsDifferent projects require different optimization options. There is no one-size-fits-all approach when it comes to optimization, but here are a few guidelines to keep in mind. Instruction selection and tuning It is very important to chose the correct architecture for instruction scheduling. By default GCC produces code is optimized for the most common processors, but if the CPU on which your code will run is known, the corresponding The option The option The General purpose optimization flags The compiler flag When code size is not an issue, The other general purpose optimization flag is Use $ gcc -frecord-gcc-switches -O3 -Wall hello.c -o hello $ readelf --string-dump=.GCC.command.line hello String dump of section '.GCC.command.line': [ 0] hello.c [ 8] -mtune=generic [ 17] -O3 [ 1b] -Wall [ 21] -frecord-gcc-switches It is very important to test and try different options with a representative data set. Often, different modules or objects can be compiled with different optimization flags in order to produce optimal results. Refer to Section 4.1.6.5, "Using Profile Feedback to Tune Optimization Heuristics." for additional optimization tuning.
4.1.6.5. Using Profile Feedback to Tune Optimization Heuristics.During the transformation of a typical set of source code into an executable, tens of hundreds of choices must be made about the importance of speed in one part of code over another, or code size as opposed to code speed. By default, these choices are made by the compiler using reasonable heuristics, tuned over time to produce the optimum runtime performance. However, GCC also has a way to teach the compiler to optimize executables for a specific machine in a specific production environment. This feature is called profile feedback. Profile feedback is used to tune optimizations such as:
Profile feedback compiles a program first to generate a program that is run and analyzed and then a second time to optimize with the gathered data. Procedure 4.4. Using Profile Feedback
Step three will use the profile information gathered in step one to tune the compiler's heuristics while optimizing the code into a final executable. Procedure 4.5. Compiling a Program with Profiling Feedback
Multiple data collection runs, as seen in step two, will accumulate data into the profiling file instead of replacing it. This allows the executable in step two to be run multiple times with additional representative data in order to collect even more information. The executable must run with representative levels of both the machine being used and a respective data set large enough for the input needed. This ensures optimal results are achieved. By default, GCC will generate the profile data into the directory where step one was performed. To generate this information elsewhere, compile with The format of the compiler feedback data file changes between compiler versions. It is imperative that the program compilation is repeated with every new version of the compiler.
4.1.6.6. Using 32-bit compilers on a 64-bit hostOn a 64-bit host, GCC will build executables that can only run on 64-bit hosts. However, GCC can be used to build executables that will run both on 64-bit hosts and on 32-bit hosts. To build 32-bit binaries on a 64-bit host, first install 32-bit versions of any supporting libraries the executable may need. This must at least include supporting libraries for There may be cases where it is useful to to install additional 32-bit libraries that a program may need. For example, if a program uses the The After the 32-bit libraries have been installed, the Procedure 4.6. Compiling a 32-bit Program on a 64-bit Host
If you have not installed the 32-bit supporting libraries you will get an error similar to this for C code: $ gcc -m32 hello32.c -o hello32 /usr/bin/ld: crt1.o: No such file: No such file or directory collect2: ld returned 1 exit status A similar error would be triggered on C++ code: $ g++ -m32 hello32.cc -o hello32-c++ In file included from /usr/include/features.h:385, from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/x86_64-redhat-linux/32/bits/os_defines.h:39, from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/x86_64-redhat-linux/32/bits/c++config.h:243, from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/iostream:39, from hello32.cc:1: /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory These errors indicate that the supporting 32-bit libraries have not been properly installed as explained at the beginning of this section. It is important to note that even if 32-bit binaries can run on 64-bit systems, it is preferrable to have 64-bit binaries unless otherwise needed. In order to run 32-bit binaries on 64-bit systems, the system must import additional 32-bit shared libraries that must be loaded in tandem with the 64-bit libraries (for example glibc). This causes additional memory usage on such systems. It is always preferrable to have 64-bit binaries for 64-bit systems and 32-bit binaries for 32-bit systems. Also important is to note that building with
4.1.7. GCC DocumentationFor more information about GCC compilers, refer to the the following online user manuals are also available: The main site for the development of GCC is gcc.gnu.org.
|
How to Install Gcc in Redhat Linux 6
Source: https://www.linuxtopia.org/online_books/rhel6/rhel_6_developer_guide/rhel_6_developer_compilers.html
0 Response to "How to Install Gcc in Redhat Linux 6"
Post a Comment