c++emacsorg-modeorg-babel

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.


Solution

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