C ++ 2010 Express Protobuf编译错误

时间:2012-08-06 03:01:23

标签: c++ protocol-buffers

我在为.lib和.dll编译protobuf源代码(2.4.1)时遇到了很多麻烦。我在自述文件中逐字逐句地阅读谷歌的内容,但gtest有重大错误。虽然,我得到libprotobuf.lib,libprotobuf-lite.lib和libprotoc.lib,确实有gtest失败的问题?此外,我可以将libprotobuf编译为.dll,但对于libprotobuf-lite.dll和libprotoc.dll,构建失败并出现错误。

我的问题:如何在msvc ++ 2010 express中使用protobuf进行编程。有没有其他人实现它?

感谢。

编辑::一些构建错误......

1>------ Build started: Project: libprotobuf, Configuration: Debug Win32 ------
2>------ Build started: Project: gtest, Configuration: Debug Win32 ------
3>------ Build started: Project: libprotobuf-lite, Configuration: Debug Win32 ------
2>  gtest.cc
3>  zero_copy_stream_impl_lite.cc
1>  zero_copy_stream_impl_lite.cc
2>c:\users\null\desktop\protobuf-2.4.1\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(745): error C3855: 'std::tr1::tuple_element': template parameter '_Idx' is incompatible with the declaration
2>c:\users\null\desktop\protobuf-2.4.1\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(757): error C2039: 'type' : is not a member of 'std::tr1::tuple_element'
2>          c:\users\null\desktop\protobuf-2.4.1\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(742) : see declaration of 'std::tr1::tuple_element'
2>c:\users\null\desktop\protobuf-2.4.1\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(757): error C2146: syntax error : missing ',' before identifier 'type'
2>c:\users\null\desktop\protobuf-2.4.1\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(757): error C2065: 'type' : undeclared identifier
2>c:\users\null\desktop\protobuf-2.4.1\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(761): error C2039: 'type' : is not a member of 'std::tr1::tuple_element'

3 个答案:

答案 0 :(得分:2)

我也有这个。感谢jahhaj指针。我尝试在gtest-tuple.h中将 tuple_element 更改为 tuple__element (双下划线)。它被使用了3次,其中一个是在评论中。

然后在Debug和Release中编译好所有内容并且所有测试都成功运行。

在编译过程中出现了一些警告,但据我所知,它们是故意或变幻莫测的Visual Studio。

答案 1 :(得分:1)

嗯,我可以告诉你问题是什么,如果不是解决方案。其中一个gtest标头定义了一个名为std::tr1::tuple_element的类。 MS定义具有完全相同名称的不同类,您可以在< utility>中找到它。头文件。我没有看到任何解决方法,除了等待谷歌这样做。这是一个reported问题。

您也可以下载pre-compiled Windows version

答案 2 :(得分:1)

我也遇到过这个问题。由于我使用Visual Studio 2010,因此实际定义了std::tr1::tuple

在README文件中阅读选择TR1元组库部分,让我尝试编译器标志-DGTEST_USE_OWN_TR1_TUPLE=0或在Visual Studio中只需GTEST_USE_OWN_TR1_TUPLE=0

这解决了我的问题,因为此元组已在Visual Studio 2010中提供的TR1功能中定义。

相关问题