C++错误"X was not declared in this scope"

C++ error "X was not declared in this scope"

本文关键字:in this declared scope was 错误 C++ not      更新时间:2023-10-16

所以我下载了这个象棋引擎:http://www.ascotti.org/programming/chess/chess.htm

,我试着编译&用eclipse运行它…但是它显示了一大堆错误…

其中在bitboard.h、hash.h和pawnash .h等多个文件中有很多'X was not declare in this scope'错误....

这个错误是什么意思,你如何从这些代码中解决这些错误?

还有很多未声明的Uint64错误,比如bitboard.h…

为什么会出现这种情况,你会如何解决它?

thx in advance

EDIT: Error LOG

**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrcsystem.o ..srcsystem.cxx
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrcposition_evaluate_pawn.o ..srcposition_evaluate_pawn.cxx
In file included from ..srcboard.h:25,
                 from ..srcposition_evaluate_pawn.cxx:23:
..srcbitboard.h:35: error: `bitCount' declared as an `inline' variable
..srcbitboard.h:35: error: `Uint64' was not declared in this scope
..srcbitboard.h:36: error: expected `,' or `;' before '{' token
..srcbitboard.h:64: error: expected `)' before "lo"
..srcbitboard.h:68: error: expected `)' before "n"
..srcbitboard.h:85: error: `Uint64' has not been declared
..srcbitboard.h:85: error: ISO C++ forbids declaration of `bb' with no type
..srcbitboard.h:103: error: `Uint64' has not been declared
..srcbitboard.h:103: error: ISO C++ forbids declaration of `bb' with no type
..srcbitboard.h:107: error: `Uint64' has not been declared
..srcbitboard.h:107: error: ISO C++ forbids declaration of `bb' with no type
..srcbitboard.h:111: error: `Uint64' has not been declared
..srcbitboard.h:111: error: ISO C++ forbids declaration of `bb' with no type
..srcbitboard.h:223: error: `Uint64' does not name a type
..srcbitboard.h: In copy constructor `BitBoard::BitBoard(const BitBoard&)':
..srcbitboard.h:73: error: `data' was not declared in this scope
..srcbitboard.h:73: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:73: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator=(const BitBoard&)':
..srcbitboard.h:82: error: `data' was not declared in this scope
..srcbitboard.h:82: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:82: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator=(int)':
..srcbitboard.h:86: error: `data' was not declared in this scope
..srcbitboard.h:86: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator&=(const BitBoard&)':
..srcbitboard.h:91: error: `data' was not declared in this scope
..srcbitboard.h:91: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:91: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator|=(const BitBoard&)':
..srcbitboard.h:95: error: `data' was not declared in this scope
..srcbitboard.h:95: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:95: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator^=(const BitBoard&)':
..srcbitboard.h:99: error: `data' was not declared in this scope
..srcbitboard.h:99: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:99: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator&=(int)':
..srcbitboard.h:104: error: `data' was not declared in this scope
..srcbitboard.h:104: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator|=(int)':
..srcbitboard.h:108: error: `data' was not declared in this scope
..srcbitboard.h:108: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::operator^=(int)':
..srcbitboard.h:112: error: `data' was not declared in this scope
..srcbitboard.h:112: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard BitBoard::operator<<(int) const':
..srcbitboard.h:116: error: `data' was not declared in this scope
..srcbitboard.h:116: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard BitBoard::operator>>(int) const':
..srcbitboard.h:120: error: `data' was not declared in this scope
..srcbitboard.h:120: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard BitBoard::operator~() const':
..srcbitboard.h:125: error: `data' was not declared in this scope
..srcbitboard.h:125: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard BitBoard::operator&(const BitBoard&) const':
..srcbitboard.h:129: error: `data' was not declared in this scope
..srcbitboard.h:129: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:129: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard BitBoard::operator|(const BitBoard&) const':
..srcbitboard.h:133: error: `data' was not declared in this scope
..srcbitboard.h:133: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:133: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard BitBoard::operator^(const BitBoard&) const':
..srcbitboard.h:137: error: `data' was not declared in this scope
..srcbitboard.h:137: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:137: warning: unused variable 'data'
..srcbitboard.h: In member function `int BitBoard::operator<(const BitBoard&) const':
..srcbitboard.h:141: error: `data' was not declared in this scope
..srcbitboard.h:141: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:141: warning: unused variable 'data'
..srcbitboard.h: In member function `int BitBoard::operator>(const BitBoard&) const':
..srcbitboard.h:145: error: `data' was not declared in this scope
..srcbitboard.h:145: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:145: warning: unused variable 'data'
..srcbitboard.h: In member function `int BitBoard::operator==(const BitBoard&) const':
..srcbitboard.h:150: error: `data' was not declared in this scope
..srcbitboard.h:150: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:150: warning: unused variable 'data'
..srcbitboard.h: In member function `int BitBoard::operator!=(const BitBoard&) const':
..srcbitboard.h:154: error: `data' was not declared in this scope
..srcbitboard.h:154: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:154: warning: unused variable 'data'
..srcbitboard.h: In member function `BitBoard::operator int() const':
..srcbitboard.h:159: error: `data' was not declared in this scope
..srcbitboard.h:159: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::setBit(unsigned int)':
..srcbitboard.h:164: error: `data' was not declared in this scope
..srcbitboard.h:164: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:164: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::clrBit(unsigned int)':
..srcbitboard.h:168: error: `data' was not declared in this scope
..srcbitboard.h:168: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:168: warning: unused variable 'data'
..srcbitboard.h: In member function `int BitBoard::getBit(unsigned int) const':
..srcbitboard.h:173: error: `data' was not declared in this scope
..srcbitboard.h:173: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:173: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::clear()':
..srcbitboard.h:178: error: `data' was not declared in this scope
..srcbitboard.h:178: warning: unused variable 'data'
..srcbitboard.h: In member function `void BitBoard::negate()':
..srcbitboard.h:182: error: `data' was not declared in this scope
..srcbitboard.h: In member function `void BitBoard::andNot(const BitBoard&)':
..srcbitboard.h:186: error: `data' was not declared in this scope
..srcbitboard.h:186: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:186: warning: unused variable 'data'
..srcbitboard.h: In member function `unsigned int BitBoard::getRank(int) const':
..srcbitboard.h:191: error: `data' was not declared in this scope
..srcbitboard.h:191: warning: unused variable 'data'
..srcbitboard.h: In member function `int BitBoard::isEmpty() const':
..srcbitboard.h:196: error: `data' was not declared in this scope
..srcbitboard.h:196: warning: unused variable 'data'
..srcbitboard.h: In member function `unsigned int BitBoard::toByte() const':
..srcbitboard.h:201: error: `data' was not declared in this scope
..srcbitboard.h:201: warning: unused variable 'data'
..srcbitboard.h: In member function `unsigned int BitBoard::toUnsigned() const':
..srcbitboard.h:206: error: `data' was not declared in this scope
..srcbitboard.h:206: warning: unused variable 'data'
..srcbitboard.h: In member function `bool BitBoard::isZero() const':
..srcbitboard.h:213: error: `data' was not declared in this scope
..srcbitboard.h:213: warning: unused variable 'data'
..srcbitboard.h: In member function `bool BitBoard::isNotZero() const':
..srcbitboard.h:217: error: `data' was not declared in this scope
..srcbitboard.h:217: warning: unused variable 'data'
..srcbitboard.h: In function `unsigned int bitSearch(BitBoard)':
..srcbitboard.h:231: error: `Uint64' was not declared in this scope
..srcbitboard.h:231: error: expected `;' before "b"
..srcbitboard.h:232: error: `b' was not declared in this scope
..srcbitboard.h:231: warning: unused variable 'Uint64'
..srcbitboard.h: In function `unsigned int bitSearchAndReset(BitBoard&)':
..srcbitboard.h:238: error: `Uint64' was not declared in this scope
..srcbitboard.h:238: error: expected `;' before "b"
..srcbitboard.h:239: error: 'class BitBoard' has no member named 'data'
..srcbitboard.h:239: error: 'class BitBoard' has no member named 'data'
..srcbitboard.h:239: error: 'class BitBoard' has no member named 'data'
..srcbitboard.h:240: error: `b' was not declared in this scope
..srcbitboard.h:238: warning: unused variable 'Uint64'
..srcbitboard.h: In function `int bitScanForward(BitBoard)':
..srcbitboard.h:246: error: 'class BitBoard' has no member named 'data'
..srcbitboard.h: In function `int bitScanAndResetForward(BitBoard&)':
..srcbitboard.h:251: error: 'class BitBoard' has no member named 'data'
..srcbitboard.h: In function `int bitCount(const BitBoard&)':
..srcbitboard.h:255: error: `int bitCount(const BitBoard&)' redeclared as different kind of symbol
..srcbitboard.h:35: error: previous declaration of `int bitCount'
..srcbitboard.h:35: error: previous non-function declaration `int bitCount'
..srcbitboard.h:255: error: conflicts with function declaration `int bitCount(const BitBoard&)'
..srcbitboard.h:256: error: 'const class BitBoard' has no member named 'data'
..srcbitboard.h:256: error: `bitCount' cannot be used as a function
..srcbitboard.h: In member function `int BitBoard::bitScanForward() const':
..srcbitboard.h:260: error: `data' was not declared in this scope
..srcbitboard.h:260: warning: unused variable 'data'
In file included from ..srcengine.h:25,
                 from ..srcposition_evaluate_pawn.cxx:25:
..srchash.h: At global scope:
..srchash.h:118: error: `Uint32' does not name a type
..srchash.h:119: error: `Uint32' does not name a type
..srchash.h: In member function `void HashTable::Entry::packData1(const Move&, unsigned int, unsigned int)':
..srchash.h:71: error: `data1' was not declared in this scope
..srchash.h:71: warning: unused variable 'data1'
..srchash.h: In member function `void HashTable::Entry::packData2(int, int)':
..srchash.h:75: error: `data2' was not declared in this scope
..srchash.h:75: warning: unused variable 'data2'
..srchash.h: In member function `unsigned int HashTable::Entry::isUpperBound() const':
..srchash.h:84: error: `data1' was not declared in this scope
..srchash.h:84: warning: unused variable 'data1'
..srchash.h: In member function `unsigned int HashTable::Entry::hasSingleReply() const':
..srchash.h:88: error: `data1' was not declared in this scope
..srchash.h:88: warning: unused variable 'data1'
..srchash.h: In member function `unsigned int HashTable::Entry::hasMateThreat() const':
..srchash.h:92: error: `data1' was not declared in this scope
..srchash.h:92: warning: unused variable 'data1'
..srchash.h: In member function `int HashTable::Entry::getValue() const':
..srchash.h:96: error: `data2' was not declared in this scope
..srchash.h:96: warning: unused variable 'data2'
..srchash.h: In member function `int HashTable::Entry::getDepth() const':
..srchash.h:100: error: `data2' was not declared in this scope
..srchash.h:100: warning: unused variable 'data2'
..srchash.h: In member function `int HashTable::Entry::getBound() const':
..srchash.h:105: error: `data1' was not declared in this scope
..srchash.h:105: warning: unused variable 'data1'
..srchash.h: In member function `unsigned int HashTable::Entry::getSearchId() const':
..srchash.h:109: error: `data1' was not declared in this scope
..srchash.h:109: warning: unused variable 'data1'
..srchash.h: In member function `Move HashTable::Entry::getMove() const':
..srchash.h:113: error: `data1' was not declared in this scope
..srchash.h:113: warning: unused variable 'data1'
..srchash.h: At global scope:
..srchash.h:176: error: `Uint32' does not name a type
In file included from ..srcengine.h:28,
                 from ..srcposition_evaluate_pawn.cxx:25:
..srcpawnhash.h:95: error: `Uint32' does not name a type
..srcpawnhash.h:96: error: `Uint32' does not name a type
..srcpawnhash.h:97: error: `Uint32' does not name a type
..srcpawnhash.h:98: error: `Uint32' does not name a type
..srcpawnhash.h: In member function `void PawnHashEntry::setFlags1(unsigned int)':
..srcpawnhash.h:71: error: `flags1' was not declared in this scope
..srcpawnhash.h:71: warning: unused variable 'flags1'
..srcpawnhash.h: In member function `void PawnHashEntry::setFlags2(unsigned int)':
..srcpawnhash.h:75: error: `flags2' was not declared in this scope
..srcpawnhash.h:75: warning: unused variable 'flags2'
..srcpawnhash.h: In member function `void PawnHashEntry::setBlackScore(int, int)':
..srcpawnhash.h:79: error: `blackScore' was not declared in this scope
..srcpawnhash.h:79: warning: unused variable 'blackScore'
..srcpawnhash.h: In member function `void PawnHashEntry::setWhiteScore(int, int)':
..srcpawnhash.h:83: error: `whiteScore' was not declared in this scope
..srcpawnhash.h:83: warning: unused variable 'whiteScore'
..srcpawnhash.h: In member function `void PawnHashEntry::reset()':
..srcpawnhash.h:87: error: `flags2' was not declared in this scope
..srcpawnhash.h:87: warning: unused variable 'flags2'
..srcpawnhash.h: In member function `unsigned int PawnHashEntry::isValid() const':
..srcpawnhash.h:92: error: `flags2' was not declared in this scope
..srcpawnhash.h:92: warning: unused variable 'flags2'
..srcposition_evaluate_pawn.cxx: In member function `PawnHashEntry* Position::evaluatePawnStructure() const':
..srcposition_evaluate_pawn.cxx:169: warning: unused variable 'f'
..srcposition_evaluate_pawn.cxx:148: warning: unused variable 'zmax'
..srcposition_evaluate_pawn.cxx:149: warning: unused variable 'zmin'
..srcposition_evaluate_pawn.cxx:260: warning: unused variable 'zmax'
..srcposition_evaluate_pawn.cxx:261: warning: unused variable 'zmin'
..srcposition_evaluate_pawn.cxx: At global scope:
..srcposition_evaluate_pawn.cxx:41: warning: 'char* sqname(int)' defined but not used
Build error occurred, build is stopped
Time consumed: 965  ms.  
<标题>编辑

这是platform.h的内容,其中的define语句是:

#ifndef PLATFORM_H_
#define PLATFORM_H_
#if defined(_MSC_VER)
#define CDECL __cdecl
#define CACHE_ALIGN __declspec(align(64))
#else
#define CDECL
#define CACHE_ALIGN
#endif
#if defined(LINUX_I386) || defined(WIN_I386) || defined(MAC_G4)
// 32-bit platform
#if defined(__GNUC__)
typedef unsigned long long  Uint64;
typedef unsigned            Uint32;
#ifndef PRIx64
#define PRIx64  "llx"
#endif
#define MK_U64( n ) n##ull
#else // Visual C++
typedef unsigned __int64    Uint64;
typedef unsigned            Uint32;
#ifndef PRIx64
#define PRIx64  "I64x"
#endif
#define MK_U64( n ) n
#endif
#endif // 32 or 64 bit platform
#endif // PLATFORM_H_

和出现错误的文件之一bitboard.h:

#ifndef BITBOARD_H_
#define BITBOARD_H_
// Note: assembly code removed in version 0.6d
#include <stdio.h>
#include "platform.h"
extern CACHE_ALIGN const unsigned int lsz64_tbl[64];
/*
    Bit count function by Gerd Isenberg.
*/
inline int bitCount( Uint64 bb )
{
   unsigned w = (unsigned) (bb >> 32);
   unsigned v = (unsigned) bb;
   v = v - ((v >> 1) & 0x55555555);
   w = w - ((w >> 1) & 0x55555555);
   v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
   w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
   v = (v + (v >> 4)) & 0x0F0F0F0F;
   w = (w + (w >> 4)) & 0x0F0F0F0F;
   v = ((v+w) * 0x01010101) >> 24;
   return v;
}
/**
    Bitboard, i.e. a 64-bit unsigned integer with some extra chess-related functions.
*/
class BitBoard
{
public:
    static const BitBoard   Clr[64];
    static const BitBoard   Set[64];
    //
    BitBoard() {
    }
    BitBoard( Uint32 lo, Uint32 hi ) {
        data = ((Uint64)hi << 32) | ((Uint64)lo);
    }
    BitBoard( Uint64 n ) {
        data = n;
    }
    BitBoard( const BitBoard & bb ) {
        data = bb.data;
    }
    //
    ~BitBoard() {
    }
    //
    void operator = ( const BitBoard & bb ) {
        data = bb.data;
    }
    void operator = ( Uint64 bb ) {
        data = bb;
    }
    //
    void operator &= ( const BitBoard & bb ) {
        data &= bb.data;
    }
    void operator |= ( const BitBoard & bb ) {
        data |= bb.data;
    }
    void operator ^= ( const BitBoard & bb ) {
        data ^= bb.data;
    }
    //
    void operator &= ( Uint64 bb ) {
        data &= bb;
    }
    void operator |= ( Uint64 bb ) {
        data |= bb;
    }
    void operator ^= ( Uint64 bb ) {
        data ^= bb;
    }
    BitBoard operator << ( int len ) const {
        return BitBoard( data << len );
    }
    BitBoard operator >> ( int len ) const {
        return BitBoard( data >> len );
    }
    //
    BitBoard operator ~ () const {
        return BitBoard( ~data );
    }
    BitBoard operator & ( const BitBoard & bb ) const {
        return BitBoard( data & bb.data );
    }
    BitBoard operator | ( const BitBoard & bb ) const {
        return BitBoard( data | bb.data );
    }
    BitBoard operator ^ ( const BitBoard & bb ) const {
        return BitBoard( data ^ bb.data );
    }
    int operator < ( const BitBoard & bb ) const {
        return data < bb.data;
    }
    int operator > ( const BitBoard & bb ) const {
        return data > bb.data;
    }
    //
    int operator == ( const BitBoard & bb ) const {
        return data == bb.data;
    }
    int operator != ( const BitBoard & bb ) const {
        return data != bb.data;
    }
    //
    operator int () const {
        return data != 0;
    }
    //
    void setBit( unsigned idx ) {
        data |= Set[idx].data;
    }
    void clrBit( unsigned idx ) {
        data &= Clr[idx].data;
    }
    //
    int getBit( unsigned idx ) const {
        return (data & Set[idx].data) != 0 ? 1 : 0;
    }
    //
    void clear( void ) {
        data = 0;
    }
    void negate( void ) {
        data = ~data;
    }
    void andNot( const BitBoard & bb ) {
        data &= ~bb.data;
    }
    //
    unsigned getRank( int rank ) const {
        return 0xFF & (unsigned)(data >> (rank*8));
    }
    //
    int isEmpty() const {
        return (data == 0);
    }
    //
    unsigned toByte( void ) const {
        return (unsigned)data & 0xFF;
    }
    //
    unsigned toUnsigned( void ) const {
        return (unsigned)data;
    }
    // Dumps this bitboard to the logfile
    void dump( const char * header = 0 ) const;
    bool isZero() const {
        return data == 0;
    }
    bool isNotZero() const {
        return data != 0;
    }
    int bitScanForward() const;
public:
    Uint64  data;
};
/*
    Bit search functions by Gerd Isenberg.
*/
inline unsigned int bitSearch( BitBoard bb )
{
   Uint64 b = bb.data ^ (bb.data - 1);
   unsigned int fold = ((unsigned)b) ^ ((unsigned)(b>>32));
   return lsz64_tbl[(fold * 0x78291ACF) >> (32-6)];
}
inline unsigned int bitSearchAndReset( BitBoard & bb )
{
    Uint64 b = bb.data ^ (bb.data - 1);
    bb.data = bb.data & (bb.data - 1);
    unsigned int fold = ((unsigned)b) ^ ((unsigned)(b>>32));
    return lsz64_tbl[(fold * 0x78291ACF) >> (32-6)];
}
inline int bitScanForward( BitBoard bb )
{
    return bb.data != 0 ? bitSearch(bb) : -1;
}
inline int bitScanAndResetForward( BitBoard & bb )
{
    return bb.data != 0 ? bitSearchAndReset(bb) : -1;
}
inline int bitCount( const BitBoard & b )
{
    return bitCount( b.data );
}
inline int BitBoard::bitScanForward() const {
    return ::bitScanForward( data );
}
#endif // BITBOARD_H_

您需要为您的平台定义Uint64Uint32(您在问题中没有提到这是什么)。

要做到这一点,你需要看看platform.h,在包含的源代码。

看起来您正在使用某些版本的GCC在某些版本的Windows上,所以我怀疑所有您需要做的是提供-DWIN_I386g++。我不知道如何处理你的构建环境。如果您使用提供的Makefile,您将使用以下行…

CC_FLAGS = -Wall -DEOF_AS_INPUT -DGCC -DLINUX_I386 -O2

…将LINUX替换为WIN

您会发现修复后,您有了一个更易于管理的警告和错误列表。她的答案修复了我在i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)中遇到的一个错误。这是一个补丁显示修复我的构建。

一旦你为你的平台修复了代码,你应该发送一个补丁给Alessandro Scotti。

享受吧!

我刚刚下载了源代码,必须打补丁才能编译:

diff --git a/pgn_lex.h b/pgn_lex.h
--- a/pgn_lex.h
+++ b/pgn_lex.h
@@ -74,7 +74,7 @@ public:
         @return token identifier
     */
-    PGNTokenId PGNLex::getNextToken();
+    PGNTokenId getNextToken();
     /** Returns the current token identifier. */
     PGNTokenId tokenId() const {

希望有帮助

这意味着之前没有声明代码中使用的标识符。它可以是任何东西一个变量,一个类型名,或者别的什么。然而,如果有问题的代码是有效的,那么可能有一些库依赖缺失。检查早期的错误。其中应该有一些"abc.h -没有这样的文件或目录"。另外,请阅读编译和安装下载的代码所需的外部库。