emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Michael Hannon <jm_hannon@yahoo.com>
Cc: Org-Mode List <emacs-orgmode@gnu.org>
Subject: Re: Details of compling and running C++ code from Org-mode?
Date: Fri, 18 Nov 2011 12:39:42 -0700	[thread overview]
Message-ID: <87vcqhgqu3.fsf@gmail.com> (raw)
In-Reply-To: 1320479064.94834.YahooMailNeo@web161908.mail.bf1.yahoo.com

Hi Michael,

Michael Hannon <jm_hannon@yahoo.com> writes:

> Greetings.  I'm curious about the process of executing a program that is
> compiled from a source block in Org-mode.
>
> Some background: I was playing with some C++ code (a slight generalization of
> some code I found in a book).  I wanted to use the "assign" method to
> initialize a vector, as:
>
>     vector<int> testVec(5, 0);
>     testVec.assign({2, 4, 6, 8, 10});
>
> It turns out that to do this one has to tell g++ (in my case) to use the
> latest version of the C++ standard.  I discovered that I could do this via:
>
>     (setq org-babel-C++-compiler "g++ -std=c++0x")
>

You could also use the :flags header argument (:flags "-std=c++0x") to
pass this flag to g++.

>
> This got me to wondering if there were any similar hooks that relate to
> running the program once it's compiled.  I looked through the list of
> org-babel* variables, but didn't find anything obvious.
>
> So what does happen when I hit C-c C-c in, say, a cpp source-code block?  The
> contents of the file are evidently written to a temporary file, after which
> the command specified by org-babel-C++-compiler is run on that file.  The
> results of the compilation are stuck some place -- another temporary file, I
> suppose.  Then the second, executable file is run and the results
> collected.

Thanks for asking this question, and sorry it took so long to respond.
I've placed an annotated copy of the relevant code up at [1] which
should explain the evaluation process for c/c++ code.  In many cases
browsing the relevant org-babel-execute:* function for your language is
the best way to discover what flags are available.

> 
> What command runs the file?

The file itself is called directly.

>   Is there any control from Org-mode over this second stage of the
> process?

Yes, the :cmdline header argument may be used to pass values to the
executing file.

Best -- Eric

>
> Thanks,
>
> -- Mike
>


Footnotes: 
[1]  http://cs.unm.edu/~eschulte/data/babel-c-execution.html
     http://cs.unm.edu/~eschulte/data/babel-c-execution.org

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

  reply	other threads:[~2011-11-18 19:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-05  7:44 Details of compling and running C++ code from Org-mode? Michael Hannon
2011-11-18 19:39 ` Eric Schulte [this message]
2011-11-18 23:07   ` [bug] " Sebastien Vauban
2011-11-19 20:27   ` Michael Hannon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vcqhgqu3.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jm_hannon@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).