Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org babel tangle file without main function

I am using the fantastic org-babel package for emacs.

I want to generate some code WITHOUT the main function in it for C++ code, but I cannot figure out how to do it.

#+begin_src C++ :tangle MyClass.h
namespace ns {
    class MyClass {};
}
#+end_src

This will generate:

int main() {
    namespace ns {
       class MyClass {};
    }
}

Is there a way I can instruct org-babel to not generate a main function? I could not find any documentation or hint anywhere.

Any alternative that lets me inline the code in the org file and tangle it without evaluation would be a solution too for my current problem.

like image 632
Germán Diago Avatar asked Sep 26 '14 21:09

Germán Diago


People also ask

How to tangle code in Babel?

With prefix argument only tangle the current code block. Choose a file to tangle. Bound to C-c C-v f . This hook is run from within code files tangled by org-babel-tangle, making it suitable for post-processing, compilation, and evaluation of code in the tangled files. Debuggers normally link errors and messages back to the source code.

What is tangle mode in org tangle?

When multiple source code blocks tangle to a single file with different and conflicting ‘ tangle-mode ’ header arguments, Org’s behavior is undefined. By default Org expands code blocks during tangling. The ‘ no-expand ’ header argument turns off such expansions.

How to tangle all source blocks in an Org file?

For example, when you want to tangle all source blocks in an Org file, include the line: Before, **header arguments** could also be specified as **separate properties** (`#+PROPERTY: tangle yes`, for example), but that syntax has been **deprecated** in the commit `90b16870` of 2013-06-23 as that was slower to fetch block properties.

How does Babel work with org?

Through extending Org with several features for editing, exporting, and executing source code, Babel transforms Org into a tool for literate programming and reproducible research. Babel augments Org code blocks by providing: code blocks as functions that accept parameters, refer to other code blocks, and can be called remotely; and


1 Answers

So I found how to do it in the documentation, finally:

:main can be set to "no" to inhibit wrapping of the code block in a main function call.

#+begin_src C++ :main no
//Code goes here
#+end_src

This will do it.

like image 174
Germán Diago Avatar answered Oct 19 '22 23:10

Germán Diago