Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Guidance on Installing and Running Protocol Buffers C++ on VS Code

46 views
Skip to first unread message

Dương Lê

unread,
Sep 13, 2024, 11:56:32 AM9/13/24
to Protocol Buffers
Hello everyone,
I’m a beginner with Protocol Buffers and I’m trying to set up my environment for C++ in Visual Studio Code. I have a few questions and would greatly appreciate your help:
1. Software Requirements: What software do I need to install to use Protocol Buffers with C++? Are there any additional tools I should be aware of?
2. Installation Guide: Could anyone share a detailed guide on how to install Protocol Buffers on Windows
3. Necessary Commands: After installation, what commands do I need to run to compile and execute a program using Protocol Buffers in C++?
I really appreciate any assistance you can provide. Thank you so much!

Aldrin

unread,
Sep 13, 2024, 2:51:36 PM9/13/24
to Protocol Buffers
Some of your questions can be answered in the "how do I start" section [1]. To fast forward your exploration through some of the links:

1. Software Requirements: There aren't any additional tools to *use* protobuf (Protocol Buffers). If you're building it, then there are some dependencies described in (2) below.
2. Installation Guide: Here is how to install protoc on windows [2]
3. Necessary Commands: "Using protobuf" consists of the following general workflow:
    A. Use `protoc` to generate source code [4] from protobuf definitions[3].
    B. Include your generated source code in your project [5]. This is essentially putting the ".h" and ".cc" files in your project and treating them like normal header and source files.
    C. Compile your project. How you do this depends on how you build your C++ code. An example using a Makefile is available in the protobuf repo [6].

As you can maybe guess, generating source code has to happen when you change your protobuf definitions (protocol definition), but isn't necessary otherwise. Everytime you compile your project, though, you need to link against the protobuf library. The example I reference above uses pkg-config which looks like this:

> >> pkg-config --cflags --libs protobuf
> -DPROTOBUF_USE_DLLS -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -I... -L... ... -labsl_log_severity

note that I omitted a whole lot of link flags and details and a whole lot of other repeated flags (unfortunate effect of how pkg-config for absl is implemented)


Reply all
Reply to author
Forward
0 new messages