VI Editor, use of the GCC compiler

Source: Internet
Author: User

The VI editor is a text editor that we use frequently under Linux, which is also intended for programmers, and basically every UNIX and Linux system provides us with this software, and we can use VI to write our code. in the VI editor all operations must be done through the keyboard and a specific shortcut key combination, the novice will not feel very easy to start learning, but this thing is very important, we first learn how to use it, master this thing to interview is also a skill. and Vim is the enhanced version of VI, the new added a lot of features.

Enter the command vi file name under the shell, for example: VI first.c, and start editing the first.c file. The VI editor has three modes, which are command mode, bottom line command mode and edit mode, and the conversion of each mode is as follows.

Command Mode ( press I to enter edit mode.) Press ":" to enter the bottom line command mode ). When we are in the VI first.c is the command mode, in this mode, we can do the following actions.
x: Delete one character
DD: Delete the line where the cursor is located
NDD: deleting n rows
P: The paste cursor follows the line, which is to paste the copied contents to the next row of the cursor.
yy: Copy cursor line
nyy: Copy n rows
u: Redo Last Action

Edit mode ( press ESC to return to command mode, and then press: to the bottom line command mode ). In the command mode when we press the I key to enter this mode, this time you can edit the text. Each character we enter will be written, unlike the command pattern, which represents a command.

Bottom Line Command mode: Support some of the following common commands, you enter these characters when you look at the bottom of the vi editor, each character will appear on the bottom line, like a single line of command window.
w: Save file
Q: Exit VI editor
! : Force
Wq: Save exit, this is what we often use, when we write the code to use this command, save exit to the shell.
q!: Force quit This is also our common use, when we have read their own code, do not want to modify the code to take effect, this is the command.
%s/str1/str2/g: Replace all str1 of the current file with str2
/str: Find string str
set Nu: Display line number on the left side of the VI Editor can display the travel number, no line number is displayed with this command.
set Nonu: line numbers are not displayed

> Well, the VI editor is talking about this, and we'll be familiar with it a few more times. Here's the GCC compiler. When we write programs in Windows, we use graphical integration tools like what vc++6.0 vs individual series, which integrate code editing, compiling, linking, and so on. However, under Linux, we have written the code we need to manually compile, link, generate the executable file. So you learn the C language under Linux you really understand it, you can learn more deeply! Let's say this tool is the GCC compiler.

GCC compiler
GCC xx.c Use this command to generate the final executable a.out (used under the shell./a.out can execute your program), he hides the following steps.
1, preprocessing: for directives
Span style= "Font-family:arial, Helvetica, Sans-serif; Font-size:large; " >2, compiling: syntax detection
3, compilation: From high-level languages- > Assembler Language

When using GCC xx.c This command we can make some changes with some option fields, and the fields commonly used are as follows:

- o Change the file name of the target such as GCC First.c-o first, the last executable file name is not a.out, but the first
- e preprocessing
-S compilation above these two options I do not know how to use, anyway, still useless.
- L link library name This is to be used, the name of the link library is generally libxxx.so, we use the-lxxx on the line.
- L Specify the path to the library this is often used.
-i specifies the path to the header file
- c only compile not link this time will not produce the executable file, but compiled after the. o File
-wall Show more warnings
-o1, O2, O3: Optimization level

Creation and use of dynamic libraries

Library is a program written by someone else. . We can't start from scratch, and we'll definitely call these well-written libraries to do something for us. The library is divided into static and dynamic libraries, all of which are used when linking. The static libraries under Windows end in. lib, and the dynamic libraries are terminated with a. dll, and Linux is terminated with. A and. So. Static libraries in the link will be embedded in the program, and the dynamic library is the program in the run time will be called, their advantages and disadvantages can be self-Baidu, Google. So let's just say how to create and use a dynamic library under Linux. dynamic libraries are also called shared libraries, It is a collection of code that provides the address in the code base when it is used.

1 Create a shared library
write source code
Compile the source code, generate the target file ADD.O. Use the command gcc-c add.c
Span style= "Font-family:arial, Helvetica, Sans-serif; Font-size:large; " > Create a shared library. Use the command gcc-shared Add.o-o libadd.so

write source code main.c
compile gcc-c main.c  
connect GCC Main.o-ladd- L.
If you run the executable directly it will be an error (because the link is only written in the executable file in the dynamic library function Address, but where the file for the dynamic library is not yet known), you need to configure the environment variable at run time ld_library_path
use command: Export ld_library_path= $LD _library_path:. that. Is my path, you can replace it with your own path.


VI Editor, use of the GCC compiler

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.