Copyright Notice: All original articles in this blog can be used for personal, educational, or non-commercial purposes, however, it is important to ensure the integrity of the article and to indicate the original author, source and this statement in the form of a hyperlink without any modification.
Blog address: Http://blog.csdn.net/shuxiao9058
Original Author: Ji ya
Have you ever thought about developing software in Linux !? I thought it may be because I am biased towards the Windows platform, or I am not very fond of writing programs in windows. I always feel that there is a layer of film between us, unlike Linux, it can be used as a powerful server. In a terminal, you only need to use simple commands to complete complicated tasks. Does it feel very advanced !? There are many other open-source projects, so do Emacs !!!
When talking about programming in Linux, we have to mention these two Editors: VI/vim and Emacs (specifically, the Emacs function is far beyond the editor, using it, we may send and receive emails, play games, and typeset ). The power of Emacs has to make us highly respect and admire the masters who have designed the editor. The power of Emacs is not only limited to editing functions, but also many custom options, in addition, we can complete our daily work without having to move the mouse (this may be impractical for most people ), the following is a brief introduction to how to use Emacs to compile/run C/C ++ programs. For more information about the commands, see my other blog posts.
Emacs has many versions, such as GNU Emacs and xemac. In addition, emacs performs well on all platforms, provided that you are familiar with it.
First, I will explain again that my operating system is RHEL 6.2, and GNU Emacs 23.1.1 and GCC version 4.4.6 have been installed. Note that Emacs is only an editor, in our programmer's opinion (in fact, we can also regard it as IDE, if you are familiar with it), at least for cainiao like me, we are not very proficient in Emacs, it is so powerful that there is a lot of knowledge to remember (not just shortcuts ).
OK. If you don't want to worry about it, go to the topic below:
1. start Emacs, enter the "Emacs &" command on the terminal, and press enter (you can also enter the "Emacs" command, but when you are using Emacs, the current terminal will not work for you; if you are familiar with Emacs, you can also enter the "emacs-NW" command to start Emacs in non-X Windows, this is the basic knowledge in Linux. After the "&" symbol is added, a sub-process will be generated under the current terminal to run Emacs without affecting the work of the current terminal, enter the "emacs-NW" command, as shown in startup interface 1;
Figure 1 startup interface of Emacs after the "emacs-NW" command is entered
2. open/create a file, enter the Emacs interface, and press "C-x C-F" to open/create a new file (2 ), we recommend that you specify the file extension specified in the C/C ++ language. Although we do not emphasize the file extension in Linux, however, if you select a proper extension, it will help to highlight the code, and Emacs will perform different languages based on the extension of the file we created (you need to know, emacs is not just designed for C/C ++ programmers) the indentation of the encoding style;
Figure 2 press "C-x C-F" and enter the file name to open/create a new file
3. edit the file and press "C-x C-s" to save the disk. The code I tested is as follows:
#include <iostream>int main( ) { std::cout << "Hello, Emacs!!!" << std::endl;}
4. Compile the file. Here I will introduce two methods.
Method 1: for general methods, refer to learning GNU Emacs. We can do this: Press "M-X". At this time, "M-X" is displayed in minibuffer, after the "compile" command is entered, the "compile command: Make-k" text is displayed by default. After "make-k" is deleted, run the relevant compilation command (for example, we should enter "G ++ test. CPP-O test "), as shown in 3;
Figure 3 enter the "G ++ test. cpp-O test" command under minibuffer to compile the source file
Method 2: I think most C/C ++ programmers will select the second compilation method. Similarly, the key is "M-x" and the "eshell" or "shell" command is entered, enter the "eshell" or "shell" buffer. The command we typed here is "eshell", and then enter "G ++ test. command CPP-O test to compile the source file, as shown in figure 4;
Figure 4 eshell: type the "G ++ test. cpp-O test" command to compile the source file
5. run the compiled executable file. Similarly, follow the steps in step 1 to open the eshell buffer and enter relevant commands to execute the compiled file. Here we should enter ". /test Command, as shown in Figure 5.
Figure 5 enter the "./test" command to execute the compiled file
Note: When we enter another buffer zone and want to switch to the edited buffer zone, type "C-B buffername" to switch to the destination buffer zone. Note that the buffer name format after editing (modification) is "* buffername *". As shown above, we switch to "test. CPP "buffer should be buffername should be" test. CPP, we have saved it before we open the "eshell" buffer and switched to "test. CPP "and then switch to the previously opened" eshell "buffer. The buffername should be" * eshell * ". We have modified this buffer;