What is the normal, correct way to use Protobuf in a VC++ project on Windows?


I’m writing a simple program that uses protobuf definitions (.proto) as part of its work. I had a lot of trouble understanding how to use protobuf in my VC++ project.

Following an online tutorial I got VS to automatically parse and generate H/CPP files from PROTO files with nothing but protoc.exe. Syntax highlighting even works and gives me nice colors in the IDE. Hooray!

enter image description here

"$(ProjectDir)../dependencies/protobuf/bin/protoc.exe" --proto_path=$(ProjectDir) --cpp_out=$(ProjectDir) %(FullPath)

However, the generated headerfiles have a lot of dependencies on other headers and inc files that I did not expect I would need (i thought I could just get around by using protoc.exe and that it would generate self-contained header files)

#include "google/protobuf/port_undef.inc"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/arenastring.h"
#include "google/protobuf/generated_message_tctable_decl.h"
#include "google/protobuf/generated_message_util.h"
...

I added the whole Protobuf release (downloaded from their github page as their instructions specify) to a nice /dependencies folder and added it as part of my "additional include directories". Now my generated files can find their dependencies… but then I hit a wall again.

Protobuf source files includes a header that is, as far as i can tell, nowhere to be found in the protobuf release. I just don’t have it!

#include "absl/strings/string_view.h" // < !!!

So I hack another thing ontop of this stuff by downloading google/absl and putting it in dependencies aswell, in additional includes;
Now I can compile, but I can’t link, because I’m missing protobuf.lib which I thought would be part of the release somewhere…. but it’s not.

I had no intention of compiling protobuf myself, I trust the developers and I just wanted to use a binary. Even if I did want to build it myself, the steps I followed feel extra convoluted and I’m not sure what I was supposed to do.

Before hacking yet another thing on top of all this to make it work I thought I’d better ask here to make sure I’m doing this the normal, intended wayYes, I have read the protobuf README as well as their website which is not an install guide and further redirects to the github readme anyway. VCPKG did not work for me.

  • Was this missing dependency normal and was I supposed to patch it by hand by fetching it myself on the internet the way I did, or was it supposed to be included/found elsewhere/part of something else that I missed?

  • Is this the normal way to install and use Protobuf, or is there supposed to be an automated way that will mostly work for a Windows VC++ setup and I made my life more complicated than necessary?

Leave a Reply

Your email address will not be published. Required fields are marked *