C++2010 Express Protobuf编译错误

C++ 2010 Express Protobuf Compiling Errors

本文关键字:错误 编译 Protobuf Express C++2010      更新时间:2023-10-16

我在为.lib和.dlls编译protobuf源代码(2.4.1)时遇到了很多问题。我逐字逐句地遵循了自述中谷歌的指示,但gtest有重大错误。尽管我得到了libprotobuf.lib、libprotobuf-lite.lib和libprotocol.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:usersnulldesktopprotobuf-2.4.1protobuf-2.4.1gtestincludegtestinternalgtest-tuple.h(745): error C3855: 'std::tr1::tuple_element': template parameter '_Idx' is incompatible with the declaration
2>c:usersnulldesktopprotobuf-2.4.1protobuf-2.4.1gtestincludegtestinternalgtest-tuple.h(757): error C2039: 'type' : is not a member of 'std::tr1::tuple_element'
2>          c:usersnulldesktopprotobuf-2.4.1protobuf-2.4.1gtestincludegtestinternalgtest-tuple.h(742) : see declaration of 'std::tr1::tuple_element'
2>c:usersnulldesktopprotobuf-2.4.1protobuf-2.4.1gtestincludegtestinternalgtest-tuple.h(757): error C2146: syntax error : missing ',' before identifier 'type'
2>c:usersnulldesktopprotobuf-2.4.1protobuf-2.4.1gtestincludegtestinternalgtest-tuple.h(757): error C2065: 'type' : undeclared identifier
2>c:usersnulldesktopprotobuf-2.4.1protobuf-2.4.1gtestincludegtestinternalgtest-tuple.h(761): error C2039: 'type' : is not a member of 'std::tr1::tuple_element'

我也有这个。感谢jahhaj的指点。我试着在gtest tuple.h中将tuple_element更改为tuple__element(双下划线)。它已经使用了3次,其中一次是在注释中

然后,在调试和发布中,一切都编译得很好,所有测试都成功运行

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

我可以告诉你问题是什么,如果不是解决方案的话。gtest头文件之一是定义一个名为std::tr1::tuple_element的类。MS定义了一个完全相同名称的不同类,您可以在<实用程序>头文件。除了等待谷歌这么做,我看不出有任何方法可以解决这个问题。这是一个已经向他们报告的问题。

或者,您可以下载预编译的Windows版本

我也遇到过这个问题。由于我使用的是Visual Studio 2010,所以实际上定义了std::tr1::tuple

阅读README文件中的选择TR1元组库部分,我将尝试使用编译器标志-DGTEST_USE_OWN_TR1_TUPLE=0,或者在Visual Studio中仅为GTEST_USE_OWN_TR1_TUPLE=0

这解决了我的问题,因为这个元组已经在VisualStudio2010中提供的TR1功能中定义了。