Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-25448

c++库编译不通过

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • None
    • None
    • Thrift
    • None

    Description

      我用自己在msys下编译了thrift0.13.0版本的lib库和compiler,用生成的compiler用当前github上最新的thrift2中的hbase.thrift文件生成了c++连接hbase的代码,然后在windows下用QtCreator建立了一个测试工程尝试编译,出现了两个错误:

      1. 

      struct TKeepDeletedCells
      {
          enum type { 
            FALSE = 0,  //此处报错:error: expected identifier before numeric constant
            TRUE = 1, 
            TTL = 2 };
      };

      错误堆栈:

      In file included from D:/Apps/Qt/Qt5.12.9/Tools/mingw730_64/x86_64-w64-mingw32/include/windef.h:8:0,
                       from D:/Apps/Qt/Qt5.12.9/Tools/mingw730_64/x86_64-w64-mingw32/include/windows.h:69,
                       from D:/Apps/Qt/Qt5.12.9/Tools/mingw730_64/x86_64-w64-mingw32/include/winsock2.h:23,
                       from ..\..\TestBoost\include/thrift/transport/PlatformSocket.h:26,
                       from ..\..\TestBoost\include/thrift/Thrift.h:23,
                       from ..\..\TestBoost\hbase-thrift2-13\Hbase_types.h:12,
                       from ..\..\TestBoost\hbase-thrift2-13\Hbase_constants.h:10,
                       from ..\..\TestBoost\hbase-thrift2-13\Hbase_constants.cpp:7:
      ..\..\TestBoost\hbase-thrift2-13\Hbase_types.h:151:17: error: expected identifier before numeric constant
           enum type { FALSE = 0, TRUE = 1, TTL = 2 };
                       ^

      错误原因:windef.h引用了头文件minwindef.h,其中对TRUE,FALSE进行了宏定义,导致此处不是一个有效的变量名

      #ifndef FALSE
      #define FALSE 0
      #endif
      
      #ifndef TRUE
      #define TRUE 1
      #endif

      我在struct TKeepDeletedCells前增加了

      #UNDEF TRUE
      #UNDEF FALSE

      规避该问题

      2. D:\Apps\Qt\Qt5.12.9\Tools\mingw730_64\lib\gcc\x86_64-w64-mingw32\7.3.0\include\c++\bits\stl_function.h:386: error: undefined reference to `apache::hadoop::hbase::thrift2::TServerName::operator<(apache::hadoop::hbase::thrift2::TServerName const&) const'

      thrift生成的TServerName定义只给出了操作符定义,并未实现

      bool operator<(const TServerName &) const;

      导致调用报错,不过我并未找到在哪里调用的<操作符,不过TServerName被放到了std:vector中,可能是vector中的函数调用了它

      我增加了该操作符的实现就可以编译通过了

      bool operator<(const TServerName &rhs) const { return startCode < rhs.startCode; };
      

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            godismortal lichaozhong
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: