This was done on Ubuntu 16.04
create a pypy virtualenv virtualenv pypy2-v5.10/bin/pypy pypy_virt
activate it source pypy_virt/bin/activate
install cppyy to pypy pip install cppyy
it downloads and builds cppyy
, cppyy-cling
, cppyy-backend
after an hour or so, there is an error about installing the backend but that makes sense since PyPy has its own It seems to run the examples like this one:
import cppyy
cppyy.cppdef("""
class MyClass {
public:
MyClass(int i) : m_data(i) {}
int m_data;
};""")
#
from cppyy.gbl import MyClass
m = MyClass(42)
cppyy.cppdef("""
void say_hello(MyClass* m) {
std::cout << "Hello, the number is: " << m->m_data << std::endl;
}""")
#
MyClass.say_hello = cppyy.gbl.say_hello
m.say_hello()
#Hello, the number is: 42
m.m_data = 13
m.say_hello()
#Hello, the number is: 13
clone clif git clone https://github.com/google/clif
read the examples/README.md
. Decide to use the install script install.sh
it requires some things apt install subversion
The instructions say to use ninja, but the version in ubuntu 16.04 is too old. They also say to use protobuf, but the version is too old so install one.
clone protobuf git clone https://github.com/google/protobuf
build and install protobuf (cd protobuf; ./autogen.sh; ./configure; make; sudo make install; sudo ldconfig)
cd into clif and start the build cd clif; ./INSTALL.sh
It will svn checkout llvm into clif_backend in the root directory (one up from clif) and build it
The script failed since the virtualenv, created by the script, does not have the protobuf module installed. Find the virtualenv (maybe $/tmp/examples/bin
?), cd into protobuf/python
in protobuf clone, and /tmp/examples/bin/python setup.py install`. Also pip install pyparsing, Now cd back and rerun
./INSTAL.sh``.
More long waiting
running the examples works. It
cppyy uses cling to create a representation of the c++ code to run through a cppyy backend, these backends need to be written for each pytohn (Cpython, PyPy) specifically for cppyy.
clif uses a parser much like cython does to create a code file that is valid c++, and is built by setuptools into a python module. The code looks something like cython where it unwraps PyObject* objects, converts them to c++ objects, then calls the original function