VC2012编译protobuf出错处理

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

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

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

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)

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

posted @ 2017-05-08 18:39  zhchoutai  阅读(605)  评论(0)    收藏  举报