Compile `.capnp` to `.py`

62 views
Skip to first unread message

Fakhri Sajadi

unread,
Feb 12, 2019, 11:23:53 AM2/12/19
to Cap'n Proto
Hi
I have a python plugin which is called in c++ code(by pybind11). when I use import exp_capnp in the plugin, the c++ codes crashed (Segmentation fault).
1. Does anyone have a solution?
2. How can I compile `.capnp` to `.py`?
Message has been deleted

Fakhri Sajadi

unread,
Feb 25, 2019, 7:53:47 AM2/25/19
to Cap'n Proto
I got new results, I found this problem comes from using capnp by python and c++ in the same project while Interface has been declared within .capnp which are used in c++ project.
 for example: 
// main.cpp
#include <pybind11/embed.h>
namespace py = pybind11;

int main() {
    py::scoped_interpreter guard{};

    py::exec(R"(
        message = "Start example"
        print(message)
        import capnp
        import address_capnp
        message = "Import address_capnp done successfully"
        print(message)
    )");
}

# address.capnp
@0x85150b117366d14b;
struct Person {
  id @0 :UInt32;
  name @1 :Text;
  email @2 :Text;
}

interface AddressMethod {
    func @0 (count: Int8 ) -> ();
}

# CMakeLists
cmake_minimum_required(VERSION 3.0)
project(example)

find_package(pybind11 REQUIRED) 
find_package(CapnProto REQUIRED) 
capnp_generate_cpp(addressSources addressHeaders address.capnp)

add_executable(example ${addressSources} main.cpp)
target_link_libraries(example PRIVATE CapnProto::capnp-rpc pybind11::embed)


The above example will work as long as interface AddressMethod in address.capnp is removed.
Can anyone help me?

Kenton Varda

unread,
Feb 25, 2019, 1:54:20 PM2/25/19
to Fakhri Sajadi, Cap'n Proto
Hi Fakhri,

Is it possible that your pycapnp plugin is compiled against a different version of libcapnp than the one you are using in C++? If so, this could certainly cause conflicts that would lead to crashes. Unfortunately, libcapnp is not ABI-compatible between versions as C++ makes ABI compatibility difficult, so it's important that all parts of your program that use libcapnp be compiled against exactly the same version.

-Kenton

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
Reply all
Reply to author
Forward
0 new messages