如何在带有预编译头文件的项目中使用 google protobuf [英] How to use google protobuf in a project with precompiled headers

查看:53
本文介绍了如何在带有预编译头文件的项目中使用 google protobuf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个项目的解决方案.我的项目(但不是全部)使用预编译的头文件.我决定使用 protobuf,但遇到了一个问题.在通过 protoc.exe 从 *.proto 生成 *.pb.h 之后,我试图包含标头并得到错误 - 预编译标头未包含在 *.pb.h 中.

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.

我该如何解决这个问题?我有一个想法(但我根本不喜欢它) - 在 protoc 生成 *.pb.h 之后,我可以运行一些脚本,它将我的预编译头文件包含到 *.pb.h 中.但我不喜欢它,因为有些项目可能不使用 PCH,而且 PCH 文件名可能不同.

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.

我知道我可以从我的项目中删除 PCH,但我也不喜欢这个想法.

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

推荐答案

我通过创建一个名为 proto-objects(不带 PCH)的静态库并在其中包含我所有的 *pb.h(cpp) 文件来解决我的问题.之后,我将该库链接到我需要 protobuf 对象的每个项目.利润!

I resolved my problem by creating a static library called proto-objects (without PCH) and including all my *pb.h(cpp) files there. After it I link that library to every project where I need my protobuf objects. Profit!

这篇关于如何在带有预编译头文件的项目中使用 google protobuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆