How to use google protobuf in a project with precompiled headers

Viewed 3574

I have a solution which contains several projects. My projects (but not all of them) use precompiled headers. I decided to use protobuf and I've met a problem. After generetaing *.pb.h from *.proto by protoc.exe I'm trying to include the header and get the error - precompiled header wasn't included into *.pb.h.

How I can solve this problem? I have an idea (but I don't like it at all) - after protoc generates *.pb.h I can run some script, which'll include my precompiled header into the *.pb.h. But I don't like it because some projects may not use PCH, and PCH file name can be different.

I understand that I can just remove PCH from my projects, but I don't like that idea too.

3 Answers

Dont add the generated myproto.pb.cc to your project. Instead, create a myproto.cpp with

#include "pch.h"
#include "myproto.pb.cc"
Related