Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile and run a C program in Emacs

Tags:

c

emacs

I can not find how to run a c program in the emacs terminal. I can compile it with M-x cc filename.c and it works fine. What is the command to run the program. M-x (what do i type).

like image 942
clay123 Avatar asked Mar 07 '12 00:03

clay123


People also ask

How do I compile C in Emacs?

To compile a program in Emacs, type Escape followed by x followed by compile, or use the pull down "tool" menu and select compile.

How do I run an EXE file in Emacs?

Executing External Commands You can execute an external shell command from within Emacs using ` M-! ' ( 'shell-command' ). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size.

How do I run an Emacs script?

If the script is executable, you can execute it with C-c C-x ( executable-interpret ). You'll be given the opportunity to pass arguments. (This command works no matter what language the program is written in, by the way, as long as the file you're editing is executable.)


2 Answers

A much better idea would be to use a Makefile

---- X Makefile X----
build:
        gcc -o exec_name input.c
run:
    ./exec_name

And then you can do M-x compile and give command as make build to compile the program and M-x compile followed by make run to run the program.

Another way of running would be M-x gdb

like image 162
vrdhn Avatar answered Oct 22 '22 00:10

vrdhn


shell-command is what you're after.

Ask Emacs about it: C-h f "shell-command". It's bound to M-!

EDIT: clarify exact action required

Do this:

M-! foo-program enter

Where foo-program is the name of the compiled executable.

like image 36
event_jr Avatar answered Oct 22 '22 00:10

event_jr