1 #+OPTIONS: H:3 num:nil toc:2 \n:nil @:t ::t |:t ^:{} -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
2 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks
3 #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n)
5 #+TITLE: Using C and C++ code with Babel
7 #+EMAIL: schulte.eric at gmail dot com, davison at stats dot ox dot ac dot uk
9 #+STYLE: <style type="text/css">#outline-container-introduction{ clear:both; }</style>
10 #+LINK_UP: ../languages.html
11 #+LINK_HOME: http://orgmode.org/worg/
14 Babel can evaluate C and C++ code. As opposed to interpreted
15 languages, which can be evaluated directly, C or C++ code is first
16 compiled to an executable which is then run. If a =main= method is
17 not present in a code block then the entire block is wrapped in a
18 trivial =main= function call.
20 So, for example, the following simple code block can be evaluated and
21 the results of evaluation inserted into the buffer.
23 : #+begin_src c++ :includes <stdio.h>
26 : printf("%d\n", a+b);
32 * Language Specific Header Arguments
33 Babel provides the following C and C++ specific header arguments:
34 - =:cmdline= :: command line arguments to pass to the executable
35 compiled from the code block
36 - =:flags= :: flags to pass to the C compiler
37 - =:main= :: can be set to "no" to inhibit wrapping of the code block
38 in a =main= function call
39 - =:includes= :: accepts either a single string name, or a list of
40 names of files to =#include= in the execution of the code block
41 - =:defines= :: just like =:includes= but for =#defines= lines at the