From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Details of compling and running C++ code from Org-mode? Date: Fri, 18 Nov 2011 12:39:42 -0700 Message-ID: <87vcqhgqu3.fsf@gmail.com> References: <1320479064.94834.YahooMailNeo@web161908.mail.bf1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRUKY-00081S-Q2 for emacs-orgmode@gnu.org; Fri, 18 Nov 2011 14:42:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RRUKX-00050G-Dn for emacs-orgmode@gnu.org; Fri, 18 Nov 2011 14:42:34 -0500 Received: from mail-yw0-f41.google.com ([209.85.213.41]:61309) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRUKX-000507-9o for emacs-orgmode@gnu.org; Fri, 18 Nov 2011 14:42:33 -0500 Received: by ywp17 with SMTP id 17so3523743ywp.0 for ; Fri, 18 Nov 2011 11:42:32 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Michael Hannon Cc: Org-Mode List Hi Michael, Michael Hannon writes: > Greetings.=C2=A0 I'm curious about the process of executing a program tha= t is > compiled from a source block in Org-mode. > > Some background: I was playing with some C++ code (a slight generalizatio= n of > some code I found in a book).=C2=A0 I wanted to use the "assign" method to > initialize a vector, as: > > =C2=A0=C2=A0=C2=A0 vector testVec(5, 0); > =C2=A0=C2=A0=C2=A0 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.=C2=A0 I discovered that I could do th= is via: > > =C2=A0=C2=A0=C2=A0 (setq org-babel-C++-compiler "g++ -std=3Dc++0x") > You could also use the :flags header argument (:flags "-std=3Dc++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.=C2=A0 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?= =C2=A0 The > contents of the file are evidently written to a temporary file, after whi= ch > the command specified by org-babel-C++-compiler is run on that file.=C2= =A0 The > results of the compilation are stuck some place -- another temporary file= , I > suppose.=C2=A0 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. >=20 > What command runs the file? The file itself is called directly. > =C2=A0 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:=20 [1] http://cs.unm.edu/~eschulte/data/babel-c-execution.html http://cs.unm.edu/~eschulte/data/babel-c-execution.org --=20 Eric Schulte http://cs.unm.edu/~eschulte/