William Everett
William Everett

Reputation: 781

How to have more than one include in org babel?

I am working with C++ in org babel and would like to know how to format the includes so that I can list more than one.

Here's what I'm trying (that fails)

#+BEGIN_SRC C++ :includes <cstdio> :includes <iostream> :includes <string>
using namespace std;
printf("Hello ");
cout << "world\n";
#+END_SRC

In this case both printf and cout are undeclared in this scope. I can drop the unnecessary :includes <string> from the headers and the cout doesn't kick up an error, so it seems like only the last :includes counts. I have tried loading multiple includes into the same line using nothing, commas and spaces as delimiters and I always get an error about extra tokens at the end of the include directive. I have also tried using :includes+ in case that worked on the header line, but it didn't.

I'm fairly certain that what I'm trying to do should be possible because it says in the documentation that

:includes
(C & CC+ only) accepts either a single string name, or a list of names of files to #include in the execution of the code block

Org-version: 8.2.7-4-g880362-elpa

EDIT:

It's worth noting that other header arguments can just be strung together (i.e. :results raw drawer will produce unformatted results in a drawer), so there's a decent chance that this is a bug. Using :include <cstdio> <iostream> produces a compiler error that there's an extra token at the end of the #include <cstdio> line.

EDIT 2:

Turns out it's actually a bug in org, so it's been submitted.

Upvotes: 1

Views: 630

Answers (1)

Tobi Schl&#252;ter
Tobi Schl&#252;ter

Reputation: 76

After some experimenting, during which I noticed that some error messages look fairly lispy, and using the superficial knowledge I have of Lisp, I found the answer:

#+begin_src C++ :includes '("<math.h>" "<iostream>" "<algorithm>")
// Freely use symbols from those headers
#+end_src

Another issue that I'm having is that I can only get it to execute if I capitalize C++ but I only get syntax highlighting if I use minuscules ("c++"). Pure joy.

Upvotes: 1

Related Questions