google protocol buffer 在windows下 编译异常还真是不少啊

google protocol buffer 在windows下 编译错误还真是不少啊!

最近用了一下 google protbuff, 打开自带的sln解决方案各种报错啊

Fatal error:
    Error detected after command was processed.
    PDB Management: Internal Error: Cannot apply file changes while file is being closed: D:\GoogleProtocolBuffer\protbuf-2.3\protobuf-2.3.0\vsprojects\Release\vc80.pdb
    Changes are associated with the following object file: D:\GoogleProtocolBuffer\protbuf-2.3\protobuf-2.3.0\vsprojects\Release\file.obj
    
    This error may be caused by multiple projects using the same PDB file.
    Please verify that multiple projects do not use the same intermediate directory.

上面是部分错误信息粘贴,意思就是说,无法打开vc80.pdb文件,后来我反复重新编译了好几次发现的每次报错的时机和文件都不一样,但都有一个共同的特点就是无法读取,无法删除,无法修改 vc80.pdb文件。

VC80.PDB   (更笼统地说就是 VCx0.PDB,其中 x 表示 Visual C++ 的版本。) 该文件存储各个 OBJ 文件的所有调试信息并与项目生成文件驻留在同一个目录中


折腾了不少时间,最后我看到gtest和gtest-main项目输出目录是在自己的目录下面,剩下的7个项目的输出目录都在同一个目录下,因为每个项目生成都会生成vc80.pdb,假如我同时一起编译的时候,vc80.pdb 正好被其中一个项目正在使用,那么下一个项目要使用这个文件就会没有权限

解决方案:把每个项目的中间文件输出目录都指定到属于自己的目录中,例如:$(ConfigurationName)\$(TargetName)\Obj




使用 visual studio 2010 编译 google protbuf项目 发现2个错误

第一个错误:

1>  gtest-filepath.cc
1>d:\googleprotocolbuffer\protbuf-2.3\protobuf-2.3.0\gtest\include\gtest\internal\gtest-tuple.h(746): error C3855: “std::tr1::tuple_element”: 模板 参数“_Idx”与声明不兼容
1>d:\googleprotocolbuffer\protbuf-2.3\protobuf-2.3.0\gtest\include\gtest\internal\gtest-tuple.h(758): error C2039: “type”: 不是“std::tr1::tuple_element”的成员
1>          d:\googleprotocolbuffer\protbuf-2.3\protobuf-2.3.0\gtest\include\gtest\internal\gtest-tuple.h(743) : 参见“std::tr1::tuple_element”的声明

解决方法:

将741行 template <int k, class Tuple> 改为 template <size_t k, class Tuple>



第二个错误:

9>  cpp_unittest.cc
9>d:\googleprotocolbuffer\protbuf-2.3\protobuf-2.3.0\src\google\protobuf\compiler\cpp\cpp_unittest.cc(812): error C2059: 语法错误:“nullptr?

查了一下MSDN 发现 nullptr是一个关键字,

812行: void* nullptr = 0;  // NULL may be integer-type, not pointer-type.

解决方法:把nullptr换个名字,下面使用到该变量的地方替换一下就解决了