【问题标题】:How to compile C++ files generated by google's protobuf compiler on OS X如何在 OS X 上编译 google 的 protobuf 编译器生成的 C++ 文件
【发布时间】:2012-03-01 23:43:24
【问题描述】:

我使用的是 Mac。我有一个用 C++ 编写的库,我们称它为“wibble”,以及它的源代码。我可以使用来自 macports (g++-mp-4.3) 的 GCC 4.3 编译此源代码,并且只要我使用 GCC 4.3,就可以将生成的库链接到其他东西。

但是,我需要将它链接到另一个应用程序(我们称之为“blort”),它只会加载使用与 OS X 10.6 捆绑的 GCC 4.2 编译的库(因为这就是 it是用)

我可以或多或少地与 wibble 的 Makefile 混淆,但我可能会喜欢,但 blort 是一个固定的目标。我可以编写我可能需要的任何代码或构建脚本将它们粘合在一起。似乎没有办法让 wibble 在 4.2 上编译(除非重写,这是不可能的),并且编写它的人证实了这一点。

我对 C++ 中的整个构建和链接过程不是很熟悉,只收到了这个集成,完全被难住了。我正在努力实现的目标是可能的吗?如果有,怎么做?

万一这很重要,我想做的是通过Inline::CPP 从 Perl 调用 wibble 中的方法,但如果必须,我愿意编写原始 XS(我已经完成了 之前,至少)。我需要使用系统 perl,以便在其他人的机器上轻松构建和安装。 :-/

更新,2012-03-01,1

我正在研究使用 Mac 的编译器编译 protobufs,并查看是否可以使用该版本的 protobufs 使用相同的编译器进行编译。我会尽快发布结果。

Hrmph同样的错误:

g++ -Wall -Wno-unused-function -Wno-long-long -pedantic -O3 -I/Users/sscaffid/local/include -L/Users/sscaffid/local/lib -fPIC -std=c++98 -c wire.pb.cc
In file included from /Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:43,
                 from wire.pb.cc:10:
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:94: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:117: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:132: error: comma at end of enumerator list
In file included from wire.pb.cc:10:
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:303: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:304: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:305: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:306: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:307: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:308: error: extra ‘;’
In file included from wire.pb.cc:11:
/Users/sscaffid/local/include/google/protobuf/descriptor.h:322: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:341: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:352: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1206: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1223: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1243: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1249: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1257: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1264: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1274: error: extra ‘;’
In file included from wire.pb.cc:13:
/Users/sscaffid/local/include/google/protobuf/wire_format.h:226: error: comma at end of enumerator list
make: *** [wire.pb.o] Error 1

【问题讨论】:

  • 4.3 中支持哪些在 4.2 中不起作用?我很惊讶需要完全重写。我想 C++ 一切皆有可能。
  • 我希望我能确定。但是,它使用 google 的 protobuf API,当我尝试在 4.2 上编译时,它在解析 protobuf 代码时完全崩溃了。
  • 我认为这不需要完全重写,而是对enums 进行简单的“修复”:删除最后一个值后的逗号。这应该可以工作,但似乎 GCC 4.2 没有(正确地)实现它。另一方面,我需要查看代码,但似乎有一个可选的分号,GCC 4.2 再次没有实现(正确)。另外,不要使用<code> 标签,使用顶部的{} 按钮来缩进代码(或按ctrl-K)。
  • 正确 - 现在可以工作了吗?
  • @Hercynium 不要修改您的问题以包含答案(并修改标题以表明它),而是让您的解决方案成为实际答案。您可以这样做。然后您可以稍后接受它作为您问题的解决方案。这一切看起来好多了。

标签: c++ macos perl gcc linker


【解决方案1】:

来自问题:

解决方案:

在 GCC 4.2 中使用-pedantic 选项会使protobuf 代码非常生气。不要使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2016-11-04
    • 2014-06-08
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多