You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cap'n Proto计算器示例编译报错:未定义main函数,求运行方法

解决Cap'n Proto计算器示例编译时的"undefined reference to 'main'"错误

Ah, I get it—you’ve successfully generated the interface code from the .capnp file, but that code only defines the data structures and RPC interfaces, not the actual program entry point (main function). That’s exactly why the linker is throwing that error. Let me walk you through getting this example up and running properly:

1. Grab the missing implementation files

The Cap'n Proto repo’s C++ samples directory includes two critical files you’re missing right now:

  • calculator-server.c++: The server implementation that hosts the calculator service logic
  • calculator-client.c++: The client that connects to the server and sends test calculation requests

Make sure you download these two files and place them in the same directory as your generated calculator.capnp.c++ and .h files.

2. Compile the server binary

Run this command to compile the server—it combines the generated interface code with the server’s actual implementation:

g++ -o calculator-server calculator.capnp.c++ calculator-server.c++ -lcapnp -lkj -lcapnp-rpc -lkj-async

3. Compile the client binary

Do the same for the client with this command:

g++ -o calculator-client calculator.capnp.c++ calculator-client.c++ -lcapnp -lkj -lcapnp-rpc -lkj-async

4. Run the calculator example

  • First, start the server in one terminal window:
    ./calculator-server
    
  • Then, open a second terminal and launch the client:
    ./calculator-client
    

You’ll see the client send a series of calculation requests to the server, and the server will process them and send back results—you should see the output printed in the client terminal.

内容的提问来源于stack exchange,提问作者LeenA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:59:51