I'm trying to execute C and/or C++ snippets in Org Babel. For example, I want to be able to execute the following snippet with C-c C-c
:
#+begin_src C
printf ("Hello World!");
#+end_src
The documentation states that there are two installation steps: (1) having a C compiler available from PATH
, and (2) having C
added to the Org Babel load languages variable.
When I do this and I try to run the above code snippet, I get the following message:
Evaluation of this C code block is disabled.
The message suggests that there is something wrong with this particular code block (the use of the world this), but other code snippets result in the same message.
Was anybody able to run C and/or C++ code blocks in Org Babel? Were more installation steps needed?
I'm using Org mode 9.1.2 and GNU Emacs 25.3.1. Org Babel code block evaluation does work for other languages (e.g., SPARQL, SML, ELisp).
org-babel-load-languages
. Double-check thatActivated
is reallyon
forC
! Is the value oforg-babel-C-compiler
meaningful on your system? – Tobias Oct 06 '17 at 20:08(eval org-babel-C-compiler)
givesgcc
. I'm not sure whatActivated
is?(eval org-babel-load-languages)
givesInvalid function: (C . t)
. – Wouter Beek Oct 06 '17 at 20:38org-babel-load-language
. Nevertheless, the(C . t)
in the error message of your attempt already shows thatC
is activated. Do you havegcc
installed on your system? – Tobias Oct 06 '17 at 23:50M-x compile
in C/C++ mode and such. – Wouter Beek Oct 07 '17 at 07:43emacs-version
is "GNU Emacs 25.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.19) of 2017-09-15". – Wouter Beek Oct 08 '17 at 12:07#+BEGIN_SRC C++
, it works for me (Emacs 25.1.1 on Mac). – AhLeung Oct 09 '17 at 08:11amitp
has observed the same behavior in at least one instance. Maybe this should become a bug report? – Wouter Beek Oct 09 '17 at 11:45M-x
org-version
which is 9.0.9 on my box. Please, add the version numbers as info to your question. – Tobias Oct 09 '17 at 11:56*.elc
and byte-compiling the sources does the trick. – Tobias Oct 09 '17 at 12:59*.elc
files in~/.emacs/elpa
, and I've uninstalled and then reinstalled org mode through the package manager (starting+closing Emacs in between these steps). The issue is still the same. Evaluation of other languages does work for me. Only not for C/C++. – Wouter Beek Oct 09 '17 at 18:10M-x
locate-library
org
andM-x
locate-library
ob-C
. – Tobias Oct 09 '17 at 20:26rm ~/.emacs/elpa/org-20171009/*.elc
and then restart Emacs. The overall issues seems to be an inconsistency between Org mode versions. Very annoying that updating/installing Org does not automatically rebuild the*.elc
files :( – Wouter Beek Oct 10 '17 at 02:00