The first step under Linux-progress bar (Gcc&makefile) __linux

Source: Internet
Author: User
I believe that all of you have written "Hello World" code in your initial study of C + +. After learning to C + + to enter the Linux system of learning we do not have to start with the "Hello World" entry-level program, after all, has a few years of experience, but to restart in a new system to write code, In particular, the complex instructions in Linux require a process of familiarity and practice. The applet for the progress bar is helpful for us to familiarize ourselves with the instructions, to practice the editing of the code in Vim, and to use tools such as GCC and makefile.

Vim has been introduced before, do not do too much to repeat, today using this small code to see how GCC and makefile are used.

First, let's take a look at what GCC is. We are already familiar with Windows vs compilers, and GCC is the compiler under Linux. The code we write is used to preprocess, compile, assemble, and link. GCC is a C-language compiler, g++ is a C + + compiler, the use of the method is basically the same. You can do this by using the following instruction format: GCC [options] to compile the file [options] [target ⽂ file].

application Example:

gcc–e hello.c–o hello.i option "-e" into the ⾏ row view, which is ⽤ to let GCC stop ⽌ the compilation process after preprocessing, the option "-O" refers to the ⽬ target ⽂ file, the ". I" ⽂ file is a preprocessed C original program.

Gcc–s Hello.i–o Hello.s uses the "-S" option to enter the ⾏ line view, which compiles only ⽽ without compiling, generating assembly code

The Gcc–c hello.s–o hello.o Assembly phase converts the compile-time ⽣ generated ". S" ⽂ file into a ⽬ target ⽂ file, where the reader can see that the assembly code has been converted to the ". O" binary ⽤ target code with the option "-C".

Makefile is a very important thing, is an essential part of learning Linux. A number of source files in a project, which are placed in several directories by type, function and module, makefile defines a set of rules to specify which files need to be compiled first, which files need to be compiled, which files need to be recompiled, and even more complex functions to operate, because Makefile is like a shell script, which can also execute operating system commands. Makefile brings the benefit is-"automated compilation", once written, only need a make command, the entire project completely automatic compilation, very ⼤ to improve the efficiency of software development. When the make command executes, a Makefile file is required to tell the make command how to compile and link the program. Makefile how to write it. Let's take a look at the makefile I wrote in the program of the progress bar.

The first thing to write is a dependency, as the first line shows, the second line is the dependency method, remember to start with the TAB key. The next step is to. Phony starts the pseudo target file, which means clean is a pseudo target file. Use made clean to make sure that all of the previous target files are compiled again.

OK, now let's see how the progress bar applet is implemented. We use # to simulate the growth of the progress, using/\-| to simulate the circle that is being loaded, and the percentage of how much progress is loaded.

Two functions were used: the Refresh function--->fflush (stdout), and the Hibernate function--->usleep (10000).

Run Result:




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.