1

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

  • Are the source code block lines above the only text in the org file? Note that you can explicitly enable and disable a programming language in org-babel-load-languages. Double-check that Activated is really on for C! Is the value of org-babel-C-compiler meaningful on your system? – Tobias Oct 6 '17 at 20:08
  • @Tobias Yes, the Org file only contains the hello world code block. (eval org-babel-C-compiler) gives gcc. I'm not sure what Activated is? (eval org-babel-load-languages) gives Invalid function: (C . t). – Wouter Beek Oct 6 '17 at 20:38
  • 1
    See that orgmode-ticket: github.com/syl20bnr/spacemacs/issues/7641. There they say that removing all the compiled files *.elc and byte-compiling the sources does the trick. – Tobias Oct 9 '17 at 12:59
  • 1
    Possible duplicate of: emacs.stackexchange.com/questions/28441/… – Tobias Oct 9 '17 at 13:01
  • 1
    The fix was to do rm ~/.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 2:00
1

The solution was basically given by @Tobias who shared the following links:

It is important to note that removing Org, restarting Emacs, and installing Org did not work for me. And C-0 M-x byte-recompile-directory RET ~/emacs.d/elpa/org-20171009 did not work either.

The only thing that worked for me was rm ~/.emacs/elpa/org-20171009/*.elc and then restart Emacs.

  • Strange. Frustrating. Glad you found something that worked. – amitp Oct 15 '17 at 15:46
0

The Evaluation of this C code block is disabled. message is produced by org-babel-check-evaluate which in turn calls org-babel-check-confirm-evaluate to do the check. See the doc strings for these functions for details. The latter function checks for :noeval headers and :eval headers with values "no" or "never" or "no-export" or "never-export". In all these cases, the evaluation is disabled.

I would instrument org-babel-check-confirm-evaluate for edebug, and step through it to find out why it is returning nil, and go from there.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.