原型“i 的多重声明” Solaris 上的错误
我正在尝试构建一个 C++ 代码,该代码使用从 Solaris 上的 proto 文件生成的 protobuf cc 文件,但收到错误“i 的多重声明”。
是否有任何解决方法可以强制 proto 不生成多个“i”声明或 CC 上的编译器标志来忽略此问题?
proto 生成的代码是:
// repeated double Prices = 22;
for (int i = 0; i < this->prices_size(); i++) {
::google::protobuf::internal::WireFormatLite::WriteDouble(
22, this->prices(i), output);
}
// repeated double Yields = 23;
for (int i = 0; i < this->yields_size(); i++) {
::google::protobuf::internal::WireFormatLite::WriteDouble(
23, this->yields(i), output);
}
这会触发错误。
谢谢, 博格丹
I am trying to build a c++ code that is using a protobuf cc file generated from a proto file on Solaris but I get the error "Multiple declaration for i".
Is there any workaround to force proto to not generate multiple declarations of "i" or a compiler flag on CC to ignore this ?
Generated code by proto is:
// repeated double Prices = 22;
for (int i = 0; i < this->prices_size(); i++) {
::google::protobuf::internal::WireFormatLite::WriteDouble(
22, this->prices(i), output);
}
// repeated double Yields = 23;
for (int i = 0; i < this->yields_size(); i++) {
::google::protobuf::internal::WireFormatLite::WriteDouble(
23, this->yields(i), output);
}
This triggers the error.
Thanks,
Bogdan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来编译器正在期待预标准 C++。根据文档,如果您在编译器的命令行上指定
-compat
或-compat=4
,就会发生这种情况,因此请确保您没有这样做。It looks like the compiler is expecting pre-standard C++. According to the documentation this will happen if you specify
-compat
or-compat=4
on the compiler's command line, so make sure you're not doing that.您使用什么版本的编译器?如果您指定
-features=localfor
,您应该具有正确的行为,但至少在当前版本的编译器中,这是默认行为,除非您指定-compat=4
>。 (但如果您出于其他原因需要-compat=4
,您仍然可以指定-features=localfor
。)What version of the compiler are you using? If you specify
-features=localfor
, you should have the correct behavior, but at least in the current versions of the compiler, this is the default unless you specify-compat=4
. (But if you need-compat=4
for other reasons, you can still specify-features=localfor
.)