0

I am new to Cap'n Proto and I was trying to compile the calculator example found here: https://github.com/capnproto/capnproto/blob/master/c%2B%2B/samples/calculator.capnp

I used this command capnp compile -oc++ calculator.capnp to generate the calculator.capnp.c++ and calculator.capnp.h files.

I tried to compile the calculator.capnp.c++ file using the following command: g++ -o calc calculator.capnp.c++ -lcapnp -lkj -lcapnp-rpc -lkj-async but I received this error message:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function '_start': (.text+0x20): undefined reference to 'main' collect2: error: ld returned 1 exit status

I went over the official documentation and other resources, but I haven't found instructions on how to run this example (or anything similar). How can I proceed and run it?

LeenA
  • 39
  • 5
  • Have you looked at the [full samples directory](https://github.com/capnproto/capnproto/tree/master/c%2B%2B/samples)? Especially the calculator [client](https://github.com/capnproto/capnproto/blob/master/c%2B%2B/samples/calculator-client.c%2B%2B) and [server](https://github.com/capnproto/capnproto/blob/master/c%2B%2B/samples/calculator-server.c%2B%2B) programs? Have you gone to [the main website](https://capnproto.org) to read its documentation? – Some programmer dude Jul 09 '19 at 10:35
  • Which "official documantation" and "other resources" did you check? Adding links to your question might be helpful. – Bodo Jul 09 '19 at 10:35
  • @Someprogrammerdude To be fair, I can't see any instructions for building & running the samples. Though by examining the contents of the files we can deduce it! – Lightness Races in Orbit Jul 09 '19 at 10:37
  • _"Time-traveling RPC: Cap’n Proto features an RPC system that implements time travel such that call results are returned to the client before the request even arrives at the server!"_ lolwut – Lightness Races in Orbit Jul 09 '19 at 10:38

1 Answers1

0

You're not building the whole sample, only the generated protocol files.

Notice how the repo also has calculator-server.c++ and calculator-client.c++, both of which contain the main entrypoint function. Pick one and link it into your program.

If you use the CMakeLists.txt already provided, this is done for you.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Thank you, but since I am very new to this, I am not sure how to "use the CMakeLists.txt" file provided. I am also not sure how to "Pick one (of the `calculator-server.c++` and `calculator-client.c++` files) and link it into your program" as you have alternatively suggested. Can you please help me out with this? – LeenA Jul 09 '19 at 10:51
  • @LeenA I can't tell you anything that I haven't already, in this format. Only you can choose which sample you wish to build and run. The server, or the client? I can't decide for you. & if you aren't familiar with CMake, you can read their documentation. – Lightness Races in Orbit Jul 09 '19 at 11:14