首页 > 解决方案 > 使用 include 中的命名空间时架构 x86_64 的未定义符号

问题描述

为这个业余问题道歉 - 我是来自 python 的 c++ 新手,并且正在努力理解我包含来自其他文件的代码的方式,以及它如何与静态声明和命名空间联系起来。

我有一个文件用于尝试使用其他人的 git repo 编译和运行测试。

我的测试文件如下所示:

#include "omp/HandEvaluator.h"
#include <iostream>
using namespace omp;

int main()
{
    omp::HandEvaluator eval;
    Hand h = Hand::empty();
    h += Hand(51) + Hand(48) + Hand(0) + Hand(1) + Hand(2);
    std::cout << eval.evaluate(h) << std::endl;
}

的 includeomp/HandEvaluator.h指的是我项目中目录中的这个文件。

当我尝试编译我的代码文件时,我得到许多像这样的“未定义符号”:

Undefined symbols for architecture x86_64:
  "omp::HandEvaluator::FLUSH_LOOKUP", referenced from:
      unsigned short omp::HandEvaluator::evaluate<true>(omp::Hand const&) const in example-a317b9.o

查看类似问题的其他答案,我认为它通常与声明有关,但这些不是已经在我带来的 omp 命名空间中定义了using namespace omp吗?

omp/HandEvaluator.h在下面:

#ifndef OMP_HAND_EVALUATOR_H
#define OMP_HAND_EVALUATOR_H

#include "Util.h"
#include "Constants.h"
#include "Hand.h"
#include <cstdint>
#include <cassert>

namespace omp {

// Evaluates hands with any number of cards up to 7.
class HandEvaluator
{
public:
    HandEvaluator();

    // Returns the rank of a hand as a 16-bit integer. Higher value is better. Can also rank hands with less than 5
    // cards. A missing card is considered the worst kicker, e.g. K < KQJT8 < A < AK < KKAQJ < AA < AA2 < AA4 < AA432.
    // Hand category can be extracted by dividing the value by 4096. 1=highcard, 2=pair, etc.
    template<bool tFlushPossible = true>
    OMP_FORCE_INLINE uint16_t evaluate(const Hand& hand) const
    {
        omp_assert(hand.count() <= 7 && hand.count() == bitCount(hand.mask()));
        if (!tFlushPossible || !hand.hasFlush()) {
            uint32_t key = hand.rankKey();
            return LOOKUP[perfHash(key)];
        } else {
            uint16_t flushKey = hand.flushKey();
            omp_assert(flushKey < FLUSH_LOOKUP_SIZE);
            return FLUSH_LOOKUP[flushKey];
        }
    }

private:
    static unsigned perfHash(unsigned key)
    {
        omp_assert(key <= MAX_KEY);
        return key + PERF_HASH_ROW_OFFSETS[key >> PERF_HASH_ROW_SHIFT];
    }

    static bool cardInit;
    static void initCardConstants();
    static void staticInit();
    static void calculatePerfectHashOffsets();
    static unsigned populateLookup(uint64_t rankCounts, unsigned ncards, unsigned handValue, unsigned endRank,
                                   unsigned maxPair, unsigned maxTrips, unsigned maxStraight, bool flush = false);
    static unsigned getKey(uint64_t rankCounts, bool flush);
    static unsigned getBiggestStraight(uint64_t rankCounts);
    static void outputTableStats(const char* name, const void* p, size_t elementSize, size_t count);

    // Rank multipliers for non-flush and flush hands.
    static const unsigned RANKS[RANK_COUNT];
    static const unsigned FLUSH_RANKS[RANK_COUNT];

    // Turn on to recalculate and output the offset array.
    static const bool RECALCULATE_PERF_HASH_OFFSETS = false;

    // Determines in how many rows the original lookup table is divided (2^shift). More rows means slightly smaller
    // lookup table but much bigger offset table.
    static const unsigned PERF_HASH_ROW_SHIFT = 12;
    static const unsigned PERF_HASH_COLUMN_MASK = (1 << PERF_HASH_ROW_SHIFT) - 1;

    // Minimum number of cards required for evaluating a hand. Can be set to higher value to decrease lookup
    // table size (requires hash recalculation).
    static const unsigned MIN_CARDS = 0;

    // Lookup tables
    static const unsigned MAX_KEY;
    static const size_t FLUSH_LOOKUP_SIZE = 8192;
    static uint16_t* ORIG_LOOKUP;
    static uint16_t LOOKUP[86547 + RECALCULATE_PERF_HASH_OFFSETS * 100000000];
    static uint16_t FLUSH_LOOKUP[FLUSH_LOOKUP_SIZE];
    static uint32_t PERF_HASH_ROW_OFFSETS[8191 + RECALCULATE_PERF_HASH_OFFSETS * 100000];
};

}

#endif // OMP_HAND_EVALUATOR_H

我已经尝试omp::HandEvaluator::FLUSH_LOOKUP根据类似的问题进行声明,但我真的不确定如何进行 - 任何能够让我指出正确方向或相关领域以更好地理解这一点的内容将不胜感激。

标签: c++namespacesundefined-symbol

解决方案


推荐阅读