emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problems running C code in org-mode under Windows
@ 2012-03-26 23:04 Richard Stanton
  2012-03-27  1:44 ` Eric Schulte
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Stanton @ 2012-03-26 23:04 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Here's a simple org file that's supposed to run some C code and print the result:

----------------------

* Sample C code

#+name: RHS.c
#+begin_src C :noweb yes :tangle RHS.c
  #include <stdio.h>
  <<main>>
#+end_src

#+name: main
#+begin_src C
  int main(int argc, char *argv[]) {
    int lst[argc-1];
    int i;
    for(i=1;i<argc;i++)
      lst[i-1] = atoi(argv[i]);
    for(i=1;i<argc;i++)
      printf("%d ", lst[i-1] + 1);
    printf("\n");
}
#+end_src

#+call: RHS.c[:cmdline 8 7 6]()

-------------------------

It works fine on my Mac, producing the result:

#+RESULTS: RHS.c[:cmdline 8 7 6]()
: 9 8 7

On my PC, however, running Windows Vista, the output is blank and there's a *Org-babel-error-output* buffer containing the message

Access is denied.
'c:/Users/stanton/AppData/Local/Temp/babel-11948MQP/C-bin-11948Nln' is not recognized as an internal or external command,
operable program or batch file.

There is a file called C-bin-11948Nln in that directory, but it has length 0, suggesting that something is going wrong in the compilation process. However, I can also see potential problems with the fact that the file name does not end in .exe, so the Windows shell is not easily going to recognize it as an executable anyway.

Does anyone have this running OK under Windows? Alternatively, how can I track down what's going wrong in more detail?

Thanks.

Richard Stanton

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problems running C code in org-mode under Windows
  2012-03-26 23:04 Problems running C code in org-mode under Windows Richard Stanton
@ 2012-03-27  1:44 ` Eric Schulte
  2012-03-27 17:25   ` Richard Stanton
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2012-03-27  1:44 UTC (permalink / raw)
  To: Richard Stanton; +Cc: emacs-orgmode@gnu.org

Richard Stanton <stanton@haas.berkeley.edu> writes:

> Here's a simple org file that's supposed to run some C code and print the result:
>
> ----------------------
>
> * Sample C code
>
> #+name: RHS.c
> #+begin_src C :noweb yes :tangle RHS.c
>   #include <stdio.h>
>   <<main>>
> #+end_src
>
> #+name: main
> #+begin_src C
>   int main(int argc, char *argv[]) {
>     int lst[argc-1];
>     int i;
>     for(i=1;i<argc;i++)
>       lst[i-1] = atoi(argv[i]);
>     for(i=1;i<argc;i++)
>       printf("%d ", lst[i-1] + 1);
>     printf("\n");
> }
> #+end_src
>
> #+call: RHS.c[:cmdline 8 7 6]()
>
> -------------------------
>
> It works fine on my Mac, producing the result:
>
> #+RESULTS: RHS.c[:cmdline 8 7 6]()
> : 9 8 7
>
> On my PC, however, running Windows Vista, the output is blank and
> there's a *Org-babel-error-output* buffer containing the message
>
> Access is denied.
> 'c:/Users/stanton/AppData/Local/Temp/babel-11948MQP/C-bin-11948Nln' is
> not recognized as an internal or external command,
> operable program or batch file.
>
> There is a file called C-bin-11948Nln in that directory, but it has
> length 0, suggesting that something is going wrong in the compilation
> process. However, I can also see potential problems with the fact that
> the file name does not end in .exe, so the Windows shell is not easily
> going to recognize it as an executable anyway.
>
> Does anyone have this running OK under Windows? Alternatively, how can
> I track down what's going wrong in more detail?
>
> Thanks.
>
> Richard Stanton
>

I don't have access to a windows machine so I can't debug this myself,
but I would suggest stepping through the execution of the
`org-babel-C-execute' function using edebug.  This is done by first
placing the cursor inside the `org-babel-C-execute' function, evaluating
the function with C-u C-M-x, then executing a C code block.  This should
give you some idea of what is going wrong where.

Best,

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problems running C code in org-mode under Windows
  2012-03-27 17:25   ` Richard Stanton
@ 2012-03-27 16:06     ` Eric Schulte
  2012-03-27 20:43       ` Richard Stanton
                         ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Eric Schulte @ 2012-03-27 16:06 UTC (permalink / raw)
  To: Richard Stanton; +Cc: emacs-orgmode@gnu.org

Thanks for tracking down the source of this problem.  Unfortunately this
is beyond my abilities to address.  It would be interesting to hear if
others on this list are having issues compiling C code blocks on
windows.  To the extent that this appears to be a problem with the Emacs
`call-process' and the cmdproxy executable maybe a bug report to Emacs
would be appropriate.

Best,

Richard Stanton <stanton@haas.berkeley.edu> writes:

> I've been tracing through, and a problem occurs when the compilation
> gets run, which is at about line 155 in file ob-eval.el, inside
> function org-babel-shell-command-on-region, where call-process region
> is called.
>
> As far as I can see, at this point the command being called is
>
> C:/emacs/emacs-24.0.94/bin/cmdproxy -c "gcc -o \"c:/users/stanton[...]C-bin-10700opx\" \"c:/users/Stanton[...]C-src-10700bfr.c\""
>
> (where [...] just means I deleted some more path information, but it's all valid).
>
> If I execute this exact command at the command line, the compilation
> works fine, and creates an executable file C-bin-10700opx.exe (note
> that gcc on Windows automatically adds the .exe extension if you omit
> it). However, after running the call-process-region command in the .el
> file, no executable file is produced, and error-file has the contents
>
> Access is denied
>
> Not sure why this should be, but the compilation is not happening.
>
>
>
>
>
>> -----Original Message-----
>> From: Eric Schulte [mailto:eric.schulte@gmx.com]
>> Sent: Monday, March 26, 2012 6:45 PM
>> To: Richard Stanton
>> Cc: emacs-orgmode@gnu.org
>> Subject: Re: [O] Problems running C code in org-mode under Windows
>> 
>> Richard Stanton <stanton@haas.berkeley.edu> writes:
>> 
>> > Here's a simple org file that's supposed to run some C code and print the
>> result:
>> >
>> > ----------------------
>> >
>> > * Sample C code
>> >
>> > #+name: RHS.c
>> > #+begin_src C :noweb yes :tangle RHS.c
>> >   #include <stdio.h>
>> >   <<main>>
>> > #+end_src
>> >
>> > #+name: main
>> > #+begin_src C
>> >   int main(int argc, char *argv[]) {
>> >     int lst[argc-1];
>> >     int i;
>> >     for(i=1;i<argc;i++)
>> >       lst[i-1] = atoi(argv[i]);
>> >     for(i=1;i<argc;i++)
>> >       printf("%d ", lst[i-1] + 1);
>> >     printf("\n");
>> > }
>> > #+end_src
>> >
>> > #+call: RHS.c[:cmdline 8 7 6]()
>> >
>> > -------------------------
>> >
>> > It works fine on my Mac, producing the result:
>> >
>> > #+RESULTS: RHS.c[:cmdline 8 7 6]()
>> > : 9 8 7
>> >
>> > On my PC, however, running Windows Vista, the output is blank and
>> > there's a *Org-babel-error-output* buffer containing the message
>> >
>> > Access is denied.
>> > 'c:/Users/stanton/AppData/Local/Temp/babel-11948MQP/C-bin-11948Nln'
>> is
>> > not recognized as an internal or external command, operable program or
>> > batch file.
>> >
>> > There is a file called C-bin-11948Nln in that directory, but it has
>> > length 0, suggesting that something is going wrong in the compilation
>> > process. However, I can also see potential problems with the fact that
>> > the file name does not end in .exe, so the Windows shell is not easily
>> > going to recognize it as an executable anyway.
>> >
>> > Does anyone have this running OK under Windows? Alternatively, how can
>> > I track down what's going wrong in more detail?
>> >
>> > Thanks.
>> >
>> > Richard Stanton
>> >
>> 
>> I don't have access to a windows machine so I can't debug this myself, but I
>> would suggest stepping through the execution of the `org-babel-C-execute'
>> function using edebug.  This is done by first placing the cursor inside the `org-
>> babel-C-execute' function, evaluating the function with C-u C-M-x, then
>> executing a C code block.  This should give you some idea of what is going
>> wrong where.
>> 
>> Best,
>> 
>> --
>> Eric Schulte
>> http://cs.unm.edu/~eschulte/

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problems running C code in org-mode under Windows
  2012-03-27  1:44 ` Eric Schulte
@ 2012-03-27 17:25   ` Richard Stanton
  2012-03-27 16:06     ` Eric Schulte
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Stanton @ 2012-03-27 17:25 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode@gnu.org

I've been tracing through, and a problem occurs when the compilation gets run, which is at about line 155 in file ob-eval.el, inside function org-babel-shell-command-on-region, where call-process region is called.

As far as I can see, at this point the command being called is

C:/emacs/emacs-24.0.94/bin/cmdproxy -c "gcc -o \"c:/users/stanton[...]C-bin-10700opx\" \"c:/users/Stanton[...]C-src-10700bfr.c\""

(where [...] just means I deleted some more path information, but it's all valid).

If I execute this exact command at the command line, the compilation works fine, and creates an executable file C-bin-10700opx.exe (note that gcc on Windows automatically adds the .exe extension if you omit it). However, after running the call-process-region command in the .el file, no executable file is produced, and error-file has the contents

Access is denied

Not sure why this should be, but the compilation is not happening.





> -----Original Message-----
> From: Eric Schulte [mailto:eric.schulte@gmx.com]
> Sent: Monday, March 26, 2012 6:45 PM
> To: Richard Stanton
> Cc: emacs-orgmode@gnu.org
> Subject: Re: [O] Problems running C code in org-mode under Windows
> 
> Richard Stanton <stanton@haas.berkeley.edu> writes:
> 
> > Here's a simple org file that's supposed to run some C code and print the
> result:
> >
> > ----------------------
> >
> > * Sample C code
> >
> > #+name: RHS.c
> > #+begin_src C :noweb yes :tangle RHS.c
> >   #include <stdio.h>
> >   <<main>>
> > #+end_src
> >
> > #+name: main
> > #+begin_src C
> >   int main(int argc, char *argv[]) {
> >     int lst[argc-1];
> >     int i;
> >     for(i=1;i<argc;i++)
> >       lst[i-1] = atoi(argv[i]);
> >     for(i=1;i<argc;i++)
> >       printf("%d ", lst[i-1] + 1);
> >     printf("\n");
> > }
> > #+end_src
> >
> > #+call: RHS.c[:cmdline 8 7 6]()
> >
> > -------------------------
> >
> > It works fine on my Mac, producing the result:
> >
> > #+RESULTS: RHS.c[:cmdline 8 7 6]()
> > : 9 8 7
> >
> > On my PC, however, running Windows Vista, the output is blank and
> > there's a *Org-babel-error-output* buffer containing the message
> >
> > Access is denied.
> > 'c:/Users/stanton/AppData/Local/Temp/babel-11948MQP/C-bin-11948Nln'
> is
> > not recognized as an internal or external command, operable program or
> > batch file.
> >
> > There is a file called C-bin-11948Nln in that directory, but it has
> > length 0, suggesting that something is going wrong in the compilation
> > process. However, I can also see potential problems with the fact that
> > the file name does not end in .exe, so the Windows shell is not easily
> > going to recognize it as an executable anyway.
> >
> > Does anyone have this running OK under Windows? Alternatively, how can
> > I track down what's going wrong in more detail?
> >
> > Thanks.
> >
> > Richard Stanton
> >
> 
> I don't have access to a windows machine so I can't debug this myself, but I
> would suggest stepping through the execution of the `org-babel-C-execute'
> function using edebug.  This is done by first placing the cursor inside the `org-
> babel-C-execute' function, evaluating the function with C-u C-M-x, then
> executing a C code block.  This should give you some idea of what is going
> wrong where.
> 
> Best,
> 
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problems running C code in org-mode under Windows
  2012-03-27 16:06     ` Eric Schulte
@ 2012-03-27 20:43       ` Richard Stanton
       [not found]       ` <0B0951AC10878A45A228603F57EEA0CE46F5DD0CBF@EXMAIL7.haas.uc.berkeley.edu>
  2012-03-28  7:14       ` Richard Stanton
  2 siblings, 0 replies; 7+ messages in thread
From: Richard Stanton @ 2012-03-27 20:43 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode@gnu.org

I think the "Access is denied" problem is probably the same as that listed here:

http://lists.gnu.org/archive/html/help-gnu-emacs/2010-04/msg00247.html

Unfortunately, when I switch to using bash as my shell under Windows, this causes problems with python-mode (though this is not really your problem...) This change does get the compilation to work on my machine, however, and a .exe file is created. So far so good...

However, the output still appears blank in the org buffer. More tracing required...



> -----Original Message-----
> From: Eric Schulte [mailto:eric.schulte@gmx.com]
> Sent: Tuesday, March 27, 2012 9:06 AM
> To: Richard Stanton
> Cc: emacs-orgmode@gnu.org
> Subject: Re: [O] Problems running C code in org-mode under Windows
> 
> Thanks for tracking down the source of this problem.  Unfortunately this is
> beyond my abilities to address.  It would be interesting to hear if others on
> this list are having issues compiling C code blocks on windows.  To the extent
> that this appears to be a problem with the Emacs `call-process' and the
> cmdproxy executable maybe a bug report to Emacs would be appropriate.
> 
> Best,
> 
> Richard Stanton <stanton@haas.berkeley.edu> writes:
> 
> > I've been tracing through, and a problem occurs when the compilation
> > gets run, which is at about line 155 in file ob-eval.el, inside
> > function org-babel-shell-command-on-region, where call-process region
> > is called.
> >
> > As far as I can see, at this point the command being called is
> >
> > C:/emacs/emacs-24.0.94/bin/cmdproxy -c "gcc -o \"c:/users/stanton[...]C-
> bin-10700opx\" \"c:/users/Stanton[...]C-src-10700bfr.c\""
> >
> > (where [...] just means I deleted some more path information, but it's all
> valid).
> >
> > If I execute this exact command at the command line, the compilation
> > works fine, and creates an executable file C-bin-10700opx.exe (note
> > that gcc on Windows automatically adds the .exe extension if you omit
> > it). However, after running the call-process-region command in the .el
> > file, no executable file is produced, and error-file has the contents
> >
> > Access is denied
> >
> > Not sure why this should be, but the compilation is not happening.
> >
> >
> >
> >
> >
> >> -----Original Message-----
> >> From: Eric Schulte [mailto:eric.schulte@gmx.com]
> >> Sent: Monday, March 26, 2012 6:45 PM
> >> To: Richard Stanton
> >> Cc: emacs-orgmode@gnu.org
> >> Subject: Re: [O] Problems running C code in org-mode under Windows
> >>
> >> Richard Stanton <stanton@haas.berkeley.edu> writes:
> >>
> >> > Here's a simple org file that's supposed to run some C code and
> >> > print the
> >> result:
> >> >
> >> > ----------------------
> >> >
> >> > * Sample C code
> >> >
> >> > #+name: RHS.c
> >> > #+begin_src C :noweb yes :tangle RHS.c
> >> >   #include <stdio.h>
> >> >   <<main>>
> >> > #+end_src
> >> >
> >> > #+name: main
> >> > #+begin_src C
> >> >   int main(int argc, char *argv[]) {
> >> >     int lst[argc-1];
> >> >     int i;
> >> >     for(i=1;i<argc;i++)
> >> >       lst[i-1] = atoi(argv[i]);
> >> >     for(i=1;i<argc;i++)
> >> >       printf("%d ", lst[i-1] + 1);
> >> >     printf("\n");
> >> > }
> >> > #+end_src
> >> >
> >> > #+call: RHS.c[:cmdline 8 7 6]()
> >> >
> >> > -------------------------
> >> >
> >> > It works fine on my Mac, producing the result:
> >> >
> >> > #+RESULTS: RHS.c[:cmdline 8 7 6]()
> >> > : 9 8 7
> >> >
> >> > On my PC, however, running Windows Vista, the output is blank and
> >> > there's a *Org-babel-error-output* buffer containing the message
> >> >
> >> > Access is denied.
> >> > 'c:/Users/stanton/AppData/Local/Temp/babel-11948MQP/C-bin-
> 11948Nln'
> >> is
> >> > not recognized as an internal or external command, operable program
> >> > or batch file.
> >> >
> >> > There is a file called C-bin-11948Nln in that directory, but it has
> >> > length 0, suggesting that something is going wrong in the
> >> > compilation process. However, I can also see potential problems
> >> > with the fact that the file name does not end in .exe, so the
> >> > Windows shell is not easily going to recognize it as an executable
> anyway.
> >> >
> >> > Does anyone have this running OK under Windows? Alternatively, how
> >> > can I track down what's going wrong in more detail?
> >> >
> >> > Thanks.
> >> >
> >> > Richard Stanton
> >> >
> >>
> >> I don't have access to a windows machine so I can't debug this
> >> myself, but I would suggest stepping through the execution of the `org-
> babel-C-execute'
> >> function using edebug.  This is done by first placing the cursor
> >> inside the `org- babel-C-execute' function, evaluating the function
> >> with C-u C-M-x, then executing a C code block.  This should give you
> >> some idea of what is going wrong where.
> >>
> >> Best,
> >>
> >> --
> >> Eric Schulte
> >> http://cs.unm.edu/~eschulte/
> 
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problems running C code in org-mode under Windows
       [not found]       ` <0B0951AC10878A45A228603F57EEA0CE46F5DD0CBF@EXMAIL7.haas.uc.berkeley.edu>
@ 2012-03-28  6:00         ` Richard Stanton
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Stanton @ 2012-03-28  6:00 UTC (permalink / raw)
  To: 'Eric Schulte'; +Cc: 'emacs-orgmode@gnu.org'

> I think the "Access is denied" problem is probably the same as that listed
> here:
> 
> http://lists.gnu.org/archive/html/help-gnu-emacs/2010-04/msg00247.html
> 
> Unfortunately, when I switch to using bash as my shell under Windows, this
> causes problems with python-mode (though this is not really your
> problem...) This change does get the compilation to work on my machine,
> however, and a .exe file is created. So far so good...
> 
> However, the output still appears blank in the org buffer. More tracing
> required...

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...

One question - why create a temp file for the executable before running the compilation? Why not just have it created by the compiler?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Problems running C code in org-mode under Windows
  2012-03-27 16:06     ` Eric Schulte
  2012-03-27 20:43       ` Richard Stanton
       [not found]       ` <0B0951AC10878A45A228603F57EEA0CE46F5DD0CBF@EXMAIL7.haas.uc.berkeley.edu>
@ 2012-03-28  7:14       ` Richard Stanton
  2 siblings, 0 replies; 7+ messages in thread
From: Richard Stanton @ 2012-03-28  7:14 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode@gnu.org

> > As far as I can see, at this point the command being called is
> >
> > C:/emacs/emacs-24.0.94/bin/cmdproxy -c "gcc -o \"c:/users/stanton[...]C-
> bin-10700opx\" \"c:/users/Stanton[...]C-src-10700bfr.c\""
> >
> > (where [...] just means I deleted some more path information, but it's all
> valid).
> >
> > If I execute this exact command at the command line, the compilation
> > works fine, and creates an executable file C-bin-10700opx.exe (note
> > that gcc on Windows automatically adds the .exe extension if you omit
> > it). However, after running the call-process-region command in the .el
> > file, no executable file is produced, and error-file has the contents
> >
> > Access is denied

In case anyone is interested, this explains why the Access Denied errors occurred, and why switching to bash solved the problem:

http://cboard.cprogramming.com/tech-board/125098-windows-7-access-denied-gcc.html

Another solution to the Access Denied problem is to put the following line in init.el:

(setq org-babel-C-compiler "gcc-4")

Then you can keep using the Window shell instead of bash. However, this still only solves part of the problem. The output is still blank.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-03-28  7:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26 23:04 Problems running C code in org-mode under Windows Richard Stanton
2012-03-27  1:44 ` Eric Schulte
2012-03-27 17:25   ` Richard Stanton
2012-03-27 16:06     ` Eric Schulte
2012-03-27 20:43       ` Richard Stanton
     [not found]       ` <0B0951AC10878A45A228603F57EEA0CE46F5DD0CBF@EXMAIL7.haas.uc.berkeley.edu>
2012-03-28  6:00         ` Richard Stanton
2012-03-28  7:14       ` Richard Stanton

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).