Using VIM to compile C + + programs in Linux

Source: Internet
Author: User

VI Three modes of explanation

Command-line mode (commands mode/general mode)
At any time, no matter what mode the user is in, just click the "ESC" key, you can get VI into the command line mode; We enter the Launch VI command under the shell environment (prompt $), which is also in this mode when you enter the editor.
In this mode, users can enter a variety of legal VI commands for managing their own documents. Any character entered from the keyboard is interpreted as an edit command, and if the input character is a valid VI command, VI completes the corresponding action after accepting the user command. Note, however, that the commands you enter are not displayed on the screen. If the input character is not a legal command of VI, VI will ring the alarm.

Text input mode (input mode/edit mode)
In command mode, enter the Insert command I (insert), attach command A (append), open command O, modify command C (change), replace command R, or replace command s to enter the text input mode. In this mode, any characters entered by the user are saved by VI as the contents of the file and displayed on the screen. In the text input process, if you want to return to the command mode, press the "ESC" key.

Final line mode (last lines mode/command mode)
The last line mode is also known as ex escape mode.
The functions of the VI and ex editors are the same, the main difference being the user interface. In VI, commands are usually a single key, such as I, A, O, etc., whereas in ex, the command is the body line that ends with a hit return. VI has a dedicated "escape" command to access many of the line-oriented ex commands. In command mode, the user presses the ":" Key to enter the last row mode, at which time VI displays a ":" As a prompt in the final row of the display window (usually the last line of the screen), waiting for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the edit buffer to a file medium). After the last command is executed, VI automatically returns to the command mode.

g++ Compile:

1. Compile (compile): refers to using the compiler (compiler) to generate a binary target file (source code), under Windows, the. obj file, under Unix is the. o file. At compile time, the compiler needs the correct syntax, the correct declaration of functions and variables, the compiler only detects program syntax, and whether functions or variables are declared, and functions do not need to be defined.

The syntax for UNIX under g++ is:
g++-C File.cpp

-C is the meaning of compile, this command will generate the FILE.O target file.

2. Link: Find the target file where the function is to be used and link them together as an executable (executable file). Link, make sure that the compiler can find all the target files that are used by the function.

g++ FILE1.O File2.o-o Program.exe

-O is the name of the executable file (output) specified for the build. If not given, the default name is A.out

The above two parts can also be completed together:

g++ file1.cpp File2.cpp-o Program.exe

This is exactly the same as the combination of the two steps above, will be the target file, and then link to file.exe

When running, you need to be aware that you must give the path name such as:./a.out Direct input a.out not run.

If only one. cpp can not generate the target file that process.

such as: g++ lin.cpp will generate a.out, can be run directly.

Attached: Linux commands

LS lists files, Ls-al,-a lists all files, including hidden files,-l long files, which include file attributes

such as Ls-al ~, lists all files under the home directory.

Using VIM to compile C + + programs in Linux

Related Article

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.