LINUX C language programming - 1

xiaoxiao2021-03-06  68

Foreword

There is a lot of software development tools in Linux issues. Many of them are developed for C and C applications. This article describes tools that can be used for C applications and commissioning under Linux. The main purpose of this article is to introduce How to use C compiler and other C programming tools under Linux, not C language programming tutorial. In this article, you will learn the following knowledge:

What is C

GNU C compiler

Use GDB to debug GCC application

You can also see other useful C programming tools issued with Linux. These tools include Pretty Print Programs, additional debugging tools, function prototype automatic buildings (Automatic Function Prototypers).

-------------------------------------------------- ------------------------------

Note: The PRETTY Print Programs automatically helps you format the source code to generate a consistent indentation format.

-------------------------------------------------- ------------------------------

What is C?

C is a widely used universal programming language in the early days of the UNIX operating system. It was first written by Dennis Ritchie, Bell Lab, for UNIX-assisted development. The language is written. From then, C will become the most widely used computer language in the world.

C can be found in the programming field:

It is a very common language. Almost you can think of at least one C compiler on the computer. And its syntax and function library are unified on different platforms, this Features are very attractive to developers.

The program with C is very fast.

C is a system language on all versions of UNIX.

C has developed greatly in the past twentieth year. A C language standard called ANSI C is released in the US National Standards Institute in the late 1980s. This is more guaranteed in different platforms in different platforms. The consistency of C. In the 1980s, a C . C will also be described in another article "C Programming" in another article.

The C compiler available on Linux is a GNU C compiler, which is based on the programming license of the Free Software Foundation, so you can freely release it. You can find it on Linux's distribution discs.

GNU C compiler

The GNU C compiler (GCC) issued with Slackware Linux is a full-featured ANSI C compatible compiler. If you are familiar with a C compiler on other operating systems or hardware platforms, you will be able to master GCC. This The section will show you how to use the GCC and some of the most common options for some GCC compilers.

Use GCC

Typically followed by some options and file names using the GCC compiler. The basic usage of the GCC command is as follows:

GCC [Options] [filenames]

The operation specified by the command line option will be executed on the file on the command line. The next section will narrate some of the option you will use.

GCC option

GCC has more than 100 compilation options available. Many of these options you may never use, but some main options will be used frequently. Many of the GCC options include more than one character. So you must be The option specifies its respective hyphens, just like most Linux commands, you cannot follow a set of options after a single hyphen. For example, the following two commands are different:

GCC -P -G Test.c

GCC -PG Test.c

The first command tells the GCC to establish a profile information for the PROF command and add the debug information to the executable file when compiling Test.c. The second command only tells the GCC to establish a profiling information for the gprof command.

When you don't have to compile a program, GCC will establish (assuming compile success) a executable name called A.out. For example, the following command will generate a file called A.out in the current directory: GCC Test.c

You can use the -o compilation option to specify a file name for the generated executable, for example, compile a C program called Count.c as a executable called count, you will enter the following The command:

GCC -O count country.c

-------------------------------------------------- ------------------------------

Note: When you use the -o option, the -o must follow a file name.

-------------------------------------------------- ------------------------------

The GCC also has the compilation options for specifying the compiler processing. The -c option tells the GCC to step only to compile the source code as the target code. This option is very frequent because it makes compiling multiple C procedures Faster and easier to manage. The target code file established by the default when the GCC has an extension.

The -s compilation option tells the GCC to stop compilation language files after the C code is generated. The default extension of the assembly language file generated by the GCC is the .s. -E option indicates that the compiler is only preprocessing the input file. When this When the option is used, the output of the preprocessor is sent to the standard output instead of being stored in the file.

Optimization option

When you use GCC to compile C code, it will try to complete compilation with the least amount of time and make the compiled code easy to debug. Easy to debug means that the compiled code is the same as the source code, and the compiled code has not been passed. Optimization. There are many options that can be used to tell GCC to generate smaller and faster executables on the basis of more compile time and sacrificial easily. These options are -O and -O2 options.

The -o option tells GCC to optimize the source code. These optimizations will make the program execute faster in most cases. -O2 option tells GCC to generate as small and as fast as possible. -O2 option will make compilation The speed is slower than using -O. But the usual code execution speed will be faster.

In addition to the -O and -O2 optimization options, there are some low-level options to generate faster code. These options are very special, and it is best to only be completely understood by these options. What is the compiled code? The effect is used again. For a detailed description of these options, please refer to the GCC's Guide page, type the Man GCC on the command line.

转载请注明原文地址:https://www.9cbs.com/read-86360.html

New Post(0)