I configure and install emacs but i don't know how to compile a c program. please give me full info.
There are a couple of ways actually. The simplest is to create a make file and place it in the same directory as your source. Then use M-x(Alt-x) to compile it. The other way is to launch a shell from within emacs using M-x eshell. The third way is to go and write a script using elisp if you are familiar with it.
Take a look at the following docs containing information on running 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
M-x compile
will by default run make. You will need to have the appropriate compiler installed, and a makefile setup to do this, though. Once this is done you can use C-x
` to go to the next error.
As already answered the compile command triggers a build which automatically routes errors to a buffer.
M-x compile
The default behavior is to run make in the directory that the file you are editing is in.
make -k
The -k means keep going on errors and make as many targets as you can. You can edit the command line at this stage.
There are two issues you might have with this setup. Firstly if your source file is not in the directory the makefile is in, then 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 issue is if you don't want a makefile. This happens if you have a simple program containing one, or only a few, cpp files, and you just want to quickly compile them.
You can do this by setting the compile-command file variable. Now when you run the compile command, this will show up as the default way to build you program, rather than make.
// -*- compile-command: "g++ -lpsapi -mwindows windowsprogram.cpp -g -o windowsprogram.exe"; -*-
Once you've compiled and possibly got some errors you can run the commands next-error and previous-error to move up and down the source file viewing them. I didn't like the default keys, and I tend to use this setup.
(global-set-key [f5] 'compile)
(global-set-key [f7] 'previous-error)
(global-set-key [f8] 'next-error)
More tips like this on my blog.