Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compiling C with Emacs
05-25-2010, 10:53 AM (This post was last modified: 05-25-2010 10:54 AM by Back_track.)
Post: #1
Compiling C with Emacs
Compiling C in Emacs 23, A tutorial.

First of all, you'll have to get Emacs. This is as simple as going to your Package Manager and finding Emacs under the Programming or Accessories location(s). Once you have downloaded Emacs, we can begin.
[Image: screenshot-emacs-sunburst.png]

Start up your Emacs and get ready to begin Smile

[Image: 62555_screenshotemacs23stevenlaptop.png]

Create a new File by
Code:
File->Visit New File->(Specify new File name WITH extension then hit Open)

I'll name this, P9.c
Start typing out your C code, mine will be this:

Code:
#include <stdio.h>

int main()
    {
    int i = 100;
    while(i!= 0)
        {
        /*99 down to 0
         *
         */
            i--;
            printf("%d\n",i);

        }

    return 0;
    }

If you don't understand this code, look it up. That is not what this is about.
The syntax highlighting should look like this if done correctly
[Image: 62556_screenshotemacs2.png]

Since your code is written, before compiling. You have to save it. The easiest way to do this is to hit the Icon that looks like a HD with an Arrow
[Image: 62557_screenshotico.png]

Once saved, we can move on to compiling.

To do this we would do as follows
Code:
Tools -> Compile
It should show up with a window on the bottom that says this:

Quote:Compile command: make -k

I've never been too fond of make files my self so lets go with the gcc commands Smile

My compilation commands are just gcc "path of file"

Code:
gcc /home/steven/Documents/EMACSC/P9.c
[Image: 62554_compilation.png]

(Optional)

If you want to run/debug your program in Emacs you could do this:

Tools->Debugger(GDB)

Once you click that, you'll get a prompt on the bottom window with something like this
Code:
Run gdb (like this): gdb --annotate=3 a.out

The parameters are just running the debugger with the default name for your executable. Once it opens Run gdb (like this): gdb --annotate=3 a.out
your program just hit the green Icon that says "GO" and it will run your program.

Happy coding Big Grin

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: