Use of GCC compiler

Source: Internet
Author: User

Source: http://www.hackerxfiles.net/

First, check whether GCC is installed on your machine and run the following command:

Run the rpm-q gcc check.

If there is no security check, check and install the following rpm
Libbinutils
Binutils
Make
Glibc-devel
Gcc-CPP
Gcc

See the following example: Test. c

# Include <stdio. h>

Main ()

{Char * STR = "I like Linux! I advices you jion in the Linux World ";

Printf ("% s", STR );

Exit (0 );

}

Compile with GCC. Run the GCC-C test. C command to compile and compile the target file. But not connected. If you enter gcc-o ../bin/test. o again, the executable file named test will be obtained. In fact, these two can not be in one breath, GCC ../bin/test. C. If the program is not wrong, it will be saved into an executable file. Maybe you will think that the command line-based compiler is inferior to the integrated development environment such as VC. It is true that the GCC interface needs to be improved, but once you are skilled, you will feel. GCC is so efficient. We can tell you that the powerful C/C ++ integrated development environment in Linux is as powerful as that in VC and uses the GCC compiler.

Gnu c compiler (GCC) is a powerful ansi c-compatible compiler. You can operate a C compiler in other operating systems to quickly master GCC, I also learned GCC soon.

1. When using gcc, GCC is based on command line. It is usually followed by some options and file names. The basic usage of GCC is as follows: the GCC [Options] [filenames] command line option setting operation will execute each given file on the command line.

2. Common GCC options

Compilation options: GCC has over 100 compilation options available. Run the man GCC command to view details.
Optimization Options: when compiling C/C ++ code with GCC, it will try to complete the compilation at least and the compiled code is easy to debug. Easy debugging means that the compiled code has the same execution sequence as the source code, and the compiled code has not been optimized. There are a lot of options to tell GCC to generate smaller and faster executable files at the expense of Compilation Time and debugging. The most typical options are-O and-O2. The-O option tells GCC to perform basic optimization on the source code. -The O2 option tells GCC to generate code as small and as fast as possible. Some special options can be viewed through man GCC.
Debugging and profiling options: GCC supports several debugging profiling options. Among these options, the-G and-PG.-G options tell GCC to generate debugging information that can be used by the GNU Debugger (such as GDB) to debug your program. -The PG option tells GCC to add additional code to the user's program. During execution, GPROF profiling information is generated to display the time consumption of the program.
3. Use GDB

Usage: In the command line, press GDB and press enter to run GDB. After GDB is started, many options can be created on the command line, you can also run GDB in the following way: when running GDB in this way, you can directly specify the program to be debugged. Run GDB-H on the command line to obtain a simple list of GDB options.
Compile the code for debugging. To make GDB work, the program must contain debugging information during compilation. The debugging information includes the types of each variable in the program, address ing in the executable file and the source code line number. GDB uses this information to associate the source code with the machine code.
Let's write so much about GCC. You can find help with a lot of Root Information. Remember to learn the man or info commands of Linux, next we will introduce how to use C/C ++ to compile makefile files and make commands for large programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.