Compilation in Emacs

I configure and install emacs, but I do not know how to compile the c program. please give me full information.

+4
source share
4 answers

Take a look at the following documents containing information on starting your compiler from emacs:

http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation.html http://www.slac.stanford.edu/comp/unix/gnu-info/emacs_26.html

+6
source

As already mentioned, the compilation team starts the assembly, which automatically sends errors to the buffer.

Mx compile 

The default behavior is to run make in the directory in which the file you are editing is located.

 make -k 

-k means keep making mistakes and make as many goals as possible. You can edit the command line at this point.

You have two problems with this setting. Firstly, if your source file is not in the directory where the make file is located, you need to set the default directory file variable. You can do this by adding a line like this at the top of the source file.

 // -*- mode: C++; default-directory: "c:/somewhere/yourmakefiledirectory/" -*- 

Another problem is that you do not want a makefile. This happens if you have a simple program containing one or more cpp files, and you just want to compile them quickly.

You can do this by setting the compilation file variable. Now, when you run the compilation command, it will appear as the default method for creating your program, and not for creating it.

 // -*- compile-command: "g++ -lpsapi -mwindows windowsprogram.cpp -g -o windowsprogram.exe"; -*- 

After you have compiled and possibly received some errors, you can run the next-error and previous-error commands to move up and down the source file that views them. I did not like the default keys, and I try to use this setting.

 (global-set-key [f5] 'compile) (global-set-key [f7] 'previous-error) (global-set-key [f8] 'next-error) 

Other tips like this on the blog .

+5
source

Mx compile will run make by default. However, you will need to install the appropriate compiler and configure makefile. Once this is done, you can use Cx `to go to the next error.

+3
source

There are actually several ways. The simplest thing is to create a make file and put it in the same directory as your source. Then use Mx (Alt-x) to compile it. Another way is to start a shell from emacs using Mx eshell. The third way is to write and write a script using elisp if you are familiar with it.

+2
source

Source: https://habr.com/ru/post/1286269/


All Articles