copyright Notice : For all original articles of this blog, to allow personal, educational and non-commercial use, but be sure to ensure the integrity of the article and do not make any changes in the form of hyperlinks to the original author, source and this statement.
Blog Address : http://blog.csdn.net/shuxiao9058
Original author : Tia
Have you ever wanted to develop software in a Linux environment completely? I have thought, perhaps because of personal bias on the Windows platform, or that the individual is not very like to write programs in Windows feel, always feel that there is a layer of film barrier to us, unlike Linux, can do a powerful server, It's very sophisticated to be able to accomplish quite complex things simply by using simple commands at the end of the terminal. There are many many open source projects, Emacs is also a bar ...
Well, when it comes to programming in Linux, we have to mention these two editors: Vi/vim and Emacs (specifically, Emacs is far beyond the editor, using it we might send and receive emails, play games, typography, etc.). The power of Emacs had to give us a great tribute and admiration for the Masters who designed the editor, the power of Emacs is not limited to editorial functions, but also provides many customization options, and we can do our daily work without having to move the mouse (which may not be realistic for most people), Below I just briefly describes how to use Emacs to compile/run C/s + + programs, the text of the relevant commands can refer to my other blog.
Emacs has many versions, such as GNU Emacs, Xemac, and so on. and Emacs can perform very well under each platform, provided you are familiar with it.
First, once again I use the operating system is RHEL 6.2, has installed the GNU Emacs 23.1.1 and GCC version 4.4.6, note that Emacs is just an editor, in our Programmer's view (in fact, we can also think of it as the IDE, If the use of more skilled, at least for my rookie, not very skilled to play the Emacs, it is too strong, so much knowledge to remember (not just shortcuts).
OK, not long-winded, the following to get to the point:
1. Start Emacs, 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 proficient with emacs, you can enter "EMACS-NW" command to start Emacs under non-X windows), as for why to add a "&", this is the basic knowledge of Linux, plus "&" will be in the current terminal generated a child process to run Emacs without any impact on the work of the current terminal, here we type "EMACS–NW" command, starting the interface as shown in Figure 1;
Figure 1 After you type the "EMACS–NW" command, the start interface for Emacs
2. Open/New file, after entering the Emacs interface, the key "C-x c-f" to open/create a new file (as shown in Figure 2), it is recommended to specify the extension of the created file with the extensions specified in the C/s + + language, although under Linux we do not very much emphasize the file extension, But if you choose a proper extension, it will help highlight the code, and Emacs will be in different languages depending on the extension of the file we created (see, Emacs is not just designed for C + + programmers) coding style indentation;
Figure 2 Key "C-x c-f", enter the filename to open/create a new file
3. Edit the file, the key "C-x c-s" disk, I test the code as follows:
#include <iostream>
int main () {
std::cout << "Hello, EMACS!!!"
<< Std::endl;
}
4. Compile the file, here I introduce two kinds of methods.
Method 1: General method, reference learning Gnu Emacs, we can do this: the key "M-x", at this time will be displayed in Minibuffer "M-x", enter the "compile" command will display "Compile Command:make-k" by default Words, when the "Make-k" deleted, run the relevant compilation commands (such as now we should type "g++ test.cpp–o test"), as shown in Figure 3;
Figure 3 Minibuffer Type the "g++ test.cpp–o Test" command to compile the source file
Law 2: I think most c/s + + programmers will choose the second compilation method, the same, the key "M-x", enter the "Eshell" or "shell" command, into the "Eshell" or "shell" buffer, where 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 Figure 4;
Figure 4 Eshell Type the "g++test.cpp–o Test" command to compile the source file
5. Run the compiled executable file, the same as in step 4th in the Open Eshell buffer, enter the relevant command to execute the compiled file, where we should enter the "./test" command, as shown in Figure 5.
Figure 5 Entering the "./test" command to execute a compiled file
Note: When we enter another buffer, we want to switch to the edited buffer and type "c-b buffername" to switch to the destination buffer. Note that the edit (modified) buffer after the name format is "*buffername*", as above we switch to "test.cpp" buffer should be 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 previous open "Eshell" buffer buffername should be "*eshell*", this buffer we have modified;