rootpy.compiled: Compiling C++

Easily compile and load C++ code from multiline Python strings or from external C++ files. The compiled libraries are cached in ~/.cache/rootpy and loaded from there when requested again.

Examples

Create the file test_compiled.cxx containing:

int AnswerToLtUaE() {
    return 42;
}

class RootpyTestCompiled {
public:
    int blah() { return 84; }
};

Now automatically compile and load that file or C++ code in a string with:

>>> import rootpy.compiled as C
>>> C.register_file("test_compiled.cxx",
...                 ["AnswerToLtUaE", "RootpyTestCompiled"])
>>> C.register_code("""
... #include <string>
... std::string _rootpy_test() { return "Hello, world"; }
... """, ["_rootpy_test"])
>>> C.AnswerToLtUaE()
42
>>> C.RootpyTestCompiled().blah()
84
>>> C._rootpy_test()
'Hello, world'

Functions

compiled.register_code Register C++ code in a multiline string
compiled.register_file Register C++ code in an external C++ file