Using glade and GTK + to develop C-language interface program under Ubuntu (ii)--GCC Common Command Introduction

Source: Internet
Author: User
Tags gtk

When it comes to Linux, no one knows GCC, and of course, the C language knows GCC, after all, all the C compilers basically have GCC to make up.

The meaning of GCC evolved over time from the original GNU C Compiler to the GNU Compiler Collection, also known as the GNU Compiler's collective. GCC's support for operating systems and hardware can be said to be: ubiquitous.

First, the GCC compilation process

The GCC compilation process is divided into four phases: the preprocessing phase, the compile stage, the assembler stage, and the link stage.

1, pre-processing phase (also known as pre-compilation stage)

GCC-E Helloworld.c-o-helloworld.i

The-e parameter above will preprocess the Helloworld.c file, and the-o parameter outputs the preprocessed file as a helloworld.i file

-E is the GCC preprocessing parameter followed by a. C Source code file

-O is the GCC output file parameter followed by the file name of the. I

2. Compile Stage

Gcc-s Helloworld.i-o Helloworld.s
-s parameter compiles the helloworld.i file to build the Helloworld.s file

The-s parameter is the GCC compilation parameter, followed by the. I file that was generated after preprocessing.

3. Assembly Stage

Gcc-c Helloworld.s-o HELLOWORLD.O
The-c parameter assembles the assembly code HELLOWORLD.S to generate the target code HELLOWORLD.O

4. Link Stage

GCC Helloworld.o-o HelloWorld
Link the helloworld.o file to generate the HelloWorld executable program

Last input

./helloworld
You can run an executable program.

For the link, there are two different forms:

(a) static links, static links rely on the dynamic link library less, the version of the dynamic link library is not too sensitive, with good compatibility, of course, the resulting program is relatively large. The file suffix of the static library is called. A

(b) Dynamic link, the generated program is relatively small, taking up less memory. The file suffix of the dynamic library is named. So

Second, with the GCC compiler for our C program written under Linux, do not need to be as exhaustive as above to compile, you can use a line of command to directly generate the executable file.
Gcc-wall-g-o HelloWorld helloworld.c
The above command compiles the HELLOWORLD.C file directly to generate the executable program HelloWorld. -O is the output parameter followed by the name of the executable file-wall open almost all common warnings of the GCC compiler, and it is strongly recommended to use this parameter during the compilation process. -wall is the most commonly used compilation warning parameter, and a compiled warning is very helpful for detecting problems with the program. The-g parameter indicates the generated target file with debug information, debugging information can be in the program when the exception exits, the moderator analyzes the source of errors, including the resulting error file name and line number and other information. Compile multiple files when you develop a program that has multiple source files, you can use the following command
GCC-WALL-G-filename1.c-filename2.c-filename3.c filename4.c Filenamex.c-o Main
The above command compiles multiple source files and generates the executable file main for compiling the source files if the header file and. c files are not in one directory, you can use the-I (uppercase I) parameter to associate files in other directories such as
Gcc-wall-g-fliename.c-i/home/filename/inc-o Main
The above command will first look for the header file in the/home/filename/inc, before it will be cited in the header file in the function and the header file in the local folder if the file in the non-library file is used in the program, for example, #include <math.h> It is also necessary to associate the corresponding library file after compilation is not an error, the associated dynamic library parameters are-l (lowercase l, not i), followed by the name of the dynamic library to be associated with, for example
Gcc-wall-g-O main-lm main.c
-LM represents the Libm.a file in the associated system library,Path is/USR/LIB/LIBM.A. The-l parameter follows the library name immediately after
The- L (uppercase L) parameter allows you to specify a specific directory in which the compiler searches for the directory before searching the system library directory
For example
Gcc-wall-g-L/lib-lhello-o HelloWorld
When the above command executes, it will first look for the library file under Lib in the current directory before looking for the required library file in the system library.


OK, here I believe that there is a preliminary understanding of the GCC compiler command, the common use of GCC commands are also given specific examples, the next article will write about the use of the make command and build your own makefile file for compiling simpler and smarter.


Using glade and GTK + to develop C-language interface program under Ubuntu (ii)--GCC Common Command Introduction

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.