VC2012编译protobuf出错处理

来源:互联网 发布:单片机编程工资 编辑:程序博客网 时间:2024/04/29 06:48

近来要学习protobuf的协议生成,需要从网上下载它的代码,从这个SVN地址下载:

http://protobuf.googlecode.com/svn/trunk

下载完成之后,就可以到protobuf\vsprojects目录下找到VC2008的工程文件,然后打开工程进行转换,这个没有问题。但在编译过程里会出现两个问题,第一个问题如下:

1>------ Build started: Project: gtest_main, Configuration: Debug Win32 ------

1>  gtest_main.cc

1>e:\protobuf\gtest\include\gtest\gtest-printers.h(556): error C2977: 'std::tuple' : too many template arguments

1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(73) : see declaration of 'std::tuple'

1>e:\my\git\protobuf\gtest\include\gtest\gtest-printers.h(564): error C2977: 'std::tuple' : too many template arguments

1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(73) : see declaration of 'std::tuple'

在这里由于使用std::tuple,并且使用的个数达到10个,因此编译提示上面的出错。只需要把std;;tuple里的个数定义为10个即可。更简单的方法是打开解决方案资源管理器,右键打开项目属性,在C/C++ --> “预处理器”--> “预处理定义中增加以下行即可:
_VARIADIC_MAX=10

VC2012_VARIADIC_MAX默认定义为5,因此不支持5个以上的参数输入,而导致出错。当然这样修改之后,编译时会多占用一点内存。

第二个问题如下:

3>------ Build started: Project: lite-test, Configuration: Debug Win32 ------

2>test_plugin.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification

2>gtestd.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in test_plugin.obj

3>  lite-test.vcxproj -> E:\protobuf\vsprojects\Debug\lite-test.exe

2>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12@std@@QAE@XZ) already defined in gtestd.lib(gtest-all.obj)

出现这个问题原因是工程在转换过程中,会有一些工程使用MD编译选项,有一些工程使用MTD编译选项,导致静态和动态连接MSVC的连接库有冲突。默认全部工程改变MTMTD编译,即可以解决。

0 0