[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Problems running C code in org-mode under Windows - SOLVED
From: |
Richard Stanton |
Subject: |
Re: [O] Problems running C code in org-mode under Windows - SOLVED |
Date: |
Thu, 29 Mar 2012 10:29:41 -0700 |
> 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).
>
> 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:
>
> (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" "")))
>
> [...]
>
> I say "partial solution" because the output in the org file is *still* blank,
> but
> at least the program does get run this way...
Solved (approximately):
Here was the org file I was using:
#+begin_src C :includes <stdio.h>
int a=2;
int b=3;
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
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.
I also suggest not creating an empty binary file and just letting the compiler
create it, unless this poses some risks I'm not seeing.
Thanks.
- Re: [O] Problems running C code in org-mode under Windows - SOLVED,
Richard Stanton <=