Emacs Compile C++/C Program < go >

Source: Internet
Author: User

1. Start Emacs and enter the "emacs&" command after the terminal (you can also enter "emacs" command, but when you use Emacs, the current terminal does not work for you, and if you are familiar with Emacs, you can also enter "EMACS-NW") command to start the non-X window of Emacs), as for why add a "&", this is the basic knowledge of Linux, plus "&" character 1. Start Emacs and enter the "emacs&" command after the terminal (you can also enter "emacs" command, but when you use Emacs, the current terminal does not work for you, and if you are familiar with Emacs, you can also enter the "EMACS-NW" command to start the non-X window of Emacs, and why add a "&" character, This is the basic knowledge of Linux, plus the "&" character will create a sub-process under the current terminal to run Emacs without any effect on the work of the current terminal, here we type "EMACS–NW" command, start interface 1, as shown in the current A sub-process is generated under the terminal to run Emacs without any effect on the work of the current terminal, where we type "EMACS–NW" command, starting with interface 1;

Figure 1 After you type the "EMACS–NW" command, the start screen of Emacs

2. Open/New file, after entering the Emacs interface, the key "C-x c-f" to open/create a new file (2), it is recommended to specify the extension of the C + + language specified file extension, although under Linux we do not emphasize the file extension, But if you choose a proper extension, it will help to highlight the code, and Emacs will be based on the extension of the file we created in different languages (to know that Emacs is not just for C + + programmer-designed) coding style indentation;

2 Keys "C-x c-f", enter a filename to open/create a new file

Write Code!

4. Compile the file, here I introduce two methods.

Method 1: General method, refer to Learning Gnu Emacs, we can do this: the key "M-x", at this point in Minibuffer will display the word "m-x", enter "compile" command after the default display "Compile Command:make-k" The word "make-k" is deleted, run the relevant compilation command (for example, we should type "g++ test.cpp–o Test"), 3;

Figure 3 Minibuffer Type "g++ test.cpp–o Test" command to compile the source file

Method 2: I think most of C + + + + programmers will choose the second method of compiling, the same, the key "M-x", enter "Eshell" or "Shell" command, enter "Eshell" or "shell" buffer, here we type the command is "Eshell", and then the same type "g++ Test.cpp–o Test "command to compile the source file as shown in 4;

Figure 4 Eshell Type "g++test.cpp–o Test" command to compile the source file

5. Run the compiled executable, the same as the 4th step in the open Eshell buffer, enter the relevant command to execute the compiled file, here we should enter the "./test" command, shown in 5.

Figure 5 Entering the "./test" command to execute the post-compilation file

Note: When we go into the other buffers, and then want to switch to the edited buffer, you can type "C-b buffername" to switch to the destination buffer. Note that after editing (modifying) the name format of the buffer is "*buffername*", as above we switch to "test.cpp" buffer should buffername should be "test.cpp", before we open the "Eshell" buffer we have saved it, Switch to "Test.cpp" and then want to switch to the previously opened "Eshell" buffer buffername should be "*eshell*", this buffer we have modified;

Emacs Compiles C++/C program < forwarding;

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.