Emacs Write Simple C program

Source: Internet
Author: User

Summary: Emacs Learning route, mingw configuration, c\c++ command-line compilation

Emacs is a powerful software, and learning Emacs is useful for a long time.

Before I started the Emacs trip, I checked the internet first. It is found that almost everyone thinks that Emacs can be very frustrating. This is against my point of view. I think the tool should not be used to toss, but to solve the problem.

So when I searched for http://blog.csdn.net/redguardtoo/article/details/7222501 (a year as a Master of Emacs) This article, the author mentioned in the article with practical questions to promote the study of the point of view suddenly attracted me , so, referring to the author's point of view, I decided not to move Emacs first, to solve the problem first, that is, what configuration is not done directly to do what I need to do.

download emacs, install, nothing changes. Then start the Quick guide ["This is necessary, otherwise do not know how to use", recorded some shortcut keys, do not have to remember all the shortcut keys, daily use will not consciously remember the usual shortcut keys of this Part I recorded almost all the shortcut keys. Address in this: HTTP://BLOG.CSDN. Net/baidu_27962861/rss/list there is a need to see.

Then, you can start using Emacs.

My real need to solve the problem is that I want to use Emacs to write some simple C language and C + + programs, and do not leave the Emacs window under the premise of the completion of programming and debugging. Writing C and C + + requires a compiler, and the common compilers are Microsoft Visual C + + and MinGW. I have both, Emacs writes C and C + + with MinGW.

First, I used Windows and installed the compiler MinGW, setting the MINGW environment variable. If you have not yet installed it, you can refer to the following steps.

1 , the officer Net: https://sourceforge.net/projects/mingw/files/find the appropriate version, download and install.

2 , and then you need to set the environment variables. because it needs to be done in the command-line mode at compile time, it cannot be compiled without setting the environment variable, because it will not prompt for internal or external commands.

Assume that the installation path is the root of the C drive, which is C:\MinGW (other directories are set according to other directories)

Click on the desktop "My Computer", select "Advanced system Settings" on the left, select "Advanced", "Environment variable", and then add in path; C:\MinGW\bin statement. Click OK.

The computer does not refresh immediately, and it may take a little while or reboot to refresh.

How do you know if it's set?

Open command Line (win+r) input cmd Enter, enter the command line, enter GCC, if not prompt gcc is not internal or external command is set up, you can also use the Gcc-v view version of the command to determine, if some version information appears to indicate that the settings.

3 , compiling instructions

How do I compile a program with this compiler?

The answer is: gcc-o "target filename" "source file name + suffix" (Note:-O is the letter O is not the number 0, some fonts they look a bit like)

Example: Assuming that there is a hello.c source file under E:\, then the steps to compile are:

-Open cmd to find the source file directory, which is e:\. Opening is not in this directory at first, it needs to be opened manually. Input e: Enter, enter the e-disk, is already the source file directory, you can use the compile command.

-Enter the information in the Gcc-o Hello hello.c observation window, if the compilation is successful, the command will be emptied, the source file directory to see the increase of hello.exe files. The target file name is freely available, not necessarily called Hello. Below is

Inside is the source code of HELLO.C

#include <stdio.h>

int main ()

{

printf ("Hello");

return 0;

}

The bottom indicates that the compilation was successful. The penultimate is the wrong command,-O can not be separated.

To the directory view, you can see more hello.exe files.

In this, we have been able to compile the program with CMD. The next step is to enter Emacs to compile.

4 , Emacs compilation

-Open Emacs, use C-x c-f to open the E:\HELLO.C, check the error, you can compile. (C means that ctrl,c-x is simultaneously pressing CTRL and X)

-In order to execute command line commands we need to open a shell, this specific what is now I do not understand, do not need to know immediately, so, first use it.

Command: M-x Shell (M refers to Zlt,m-x is ALT and x simultaneously press)

At this point, a window similar to cmd appears in Emacs, which can be compiled as if it were done in CMD. It can be done just like in CMD.

-Run the program. Also in the shell, you can run a look at the results after the compilation is complete.

Command: Tap the name of the program directly, with the suffix name.

Take the hello.c above us for example. After compiling, the hello.exe will be generated, at which point the hello.exe can be run directly in the shell.

The results are shown.

So far, it has been possible to compile and run C and C + + with Emacs. Done.

Other languages, such as Java, assembler, and Python, should be the same, with only the number of environment variables and the different compilation commands. I haven't tried to be sure yet.

Now, there is a very important issue has not been resolved, is the Chinese display will become a box problem. So, the next article will have a solution to the Chinese display.

Emacs Write Simple C program

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.