Thread: running compiled program in Emacs

  1. #1
    Registered User
    Join Date
    Aug 2011

    running compiled program in Emacs

    Hi there,

    I don't know if this is in the right place, but as emacs seems to be associated to Unix and Linux, I thought I'd give it a shot.

    Can anyone tell me how to run a file from emacs, is there a run command at all?

    it would be nice as I am learning with little snippets of code to just get it to run in a terminal window started from emacs.

    Any input is always greatly received.

    Kind regards


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    I don't use emacs, but if you are on linux, here's a tip about this kind of thing.

    Set your DE or window manager to use a hotkey to background a window, eg, ctrl-backspace.
    On the same desktop, open your editor and a terminal cd'd to the directory the editor writes to. Foreground the editor.
    Write your snippet, save it. Background the editor window. You're now looking at the terminal. Type "gcc whatever" and "./a.out".
    All you need to do now is flip back and forth with the hotkey. You don't have to keep re-typing gcc etc, just use the up-down arrow keys to access bash's command line history. This may be nicer than outputting into emacs or using a temporary pop-up terminal, because you can also scroll back to see previous runs.

    Most editors and terminal emulators allow tabbing, so you can work on multiple files output into different directories by adding new tabs to the terminal window, and each one has it's own command history, so you can have, eg, different commands in play for different languages or whatever. I do a lot of web-dev and often need to work in 2-3 languages simultaneously, with files in various places, some of them involve console output, plus doing little "premise tests", and of course distracting myself with C stuff from here. Works great.
    Last edited by MK27; 12-16-2011 at 12:06 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Aug 2011
    Thanks for your replies chaps, actually, I have been doing just that, though I am running emacs on a mac (I've gone off Xcode as it wouldn't run one of my programs that when i posted the code on a forum, everyone said was perfectly well written code.) and as a result it likes to open up in the terminal window anyway, I am just trying to learn emacs without all the arduous reading. The emacs manual is not what you would call "dyslexic friendly" so to speak.

    Kind regards


  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Just keep a shell buffer open in emacs. You can compile and run from there without leaving emacs. And you can close your xterm
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble running a compiled C file.
    By somekid413 in forum C Programming
    Replies: 2
    Last Post: 10-18-2010, 11:32 AM
  2. Problems running compiled .exe on other machines.
    By Troels Leth in forum C++ Programming
    Replies: 39
    Last Post: 05-09-2008, 05:30 AM
  3. Replies: 1
    Last Post: 03-12-2008, 12:10 AM
  4. Replies: 27
    Last Post: 10-25-2007, 10:47 AM
  5. help with compiled program
    By wraith8 in forum C Programming
    Replies: 14
    Last Post: 08-07-2003, 07:07 AM