From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Stanton Subject: Re: Problems running C code in org-mode under Windows - SOLVED Date: Thu, 29 Mar 2012 10:29:41 -0700 Message-ID: <40C7B1BFC291ED4E9D10436D07736A334702EB9BA9@EXMAIL7.haas.uc.berkeley.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:36260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJAW-0003MM-LT for emacs-orgmode@gnu.org; Thu, 29 Mar 2012 13:29:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDJAU-00047K-Pe for emacs-orgmode@gnu.org; Thu, 29 Mar 2012 13:29:52 -0400 Received: from gateway-b.haas.berkeley.edu ([128.32.222.40]:62574) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDJAU-00046q-K1 for emacs-orgmode@gnu.org; Thu, 29 Mar 2012 13:29:50 -0400 Content-Language: en-US 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: 'Eric Schulte' Cc: "'emacs-orgmode@gnu.org'" > One problem - when using bash as the shell, when trying to execute the > compiled file, it tries to execute the empty file, not the file that was = just > compiled (which has the same name, but the extension .exe, added by the > compiler). >=20 > A partial solution to this is to append ".exe" to the name of the binary = temp > file if running under Windows. E.g., start org-babel-C-execute something > like this: >=20 > (defun org-babel-C-execute (body params) > "This function should only be called by `org-babel-execute:C' > or `org-babel-execute:C++'." > (let* ((tmp-src-file (org-babel-temp-file > "C-src-" > (cond > ((equal org-babel-c-variant 'c) ".c") > ((equal org-babel-c-variant 'cpp) ".cpp")))) > (tmp-bin-file (org-babel-temp-file > "C-bin-" > (if (equal system-type 'windows-nt) ".exe" ""))) >=20 > [...] >=20 > I say "partial solution" because the output in the org file is *still* bl= ank, but > at least the program does get run this way... Solved (approximately): Here was the org file I was using: #+begin_src C :includes int a=3D2; int b=3D3; printf("%d\n", a+b); #+end_src This ran fine, but returned an error code of 2, which caused problems. When= I added the extra line =20 return(0); at the end, it ran fine. To allow for people who might be using the Cygwin bash shell in Emacs under= Windows (which is recommended by many), I do recommend making the change = I suggested above, adding the following lines to ob-C.el: > (tmp-bin-file (org-babel-temp-file > "C-bin-" > (if (equal system-type 'windows-nt) ".exe" ""))) > This prevents bash trying to run an (empty) file with no extension when the= compiler has generated a file with a ".exe" extension. Otherwise, it looks= like I now have this running fine.=20 I also suggest not creating an empty binary file and just letting the compi= ler create it, unless this poses some risks I'm not seeing. Thanks.