gpt4 book ai didi

c++ - 符号未出现在目标文件中

转载 作者:行者123 更新时间:2023-11-30 01:09:57 25 4
gpt4 key购买 nike

<分区>

由于某种原因,此文件中定义的符号之一未显示在目标文件中:

/**
* || File: random.cc
* || Project: Shatter
* || Encoding: UTF-8
* || Author: ********
*
* Copyright (C) 2016 ********** *. ****
* All rights reserved.
* Use by explicit written permission only.
*
* Changelog:
* - Aug 24, 2016, 07:35:22 PM --- File was created by ********
*
*/

#include <shatter/random/random.h>

// @TODO: MOVE TO <config-build.h>
#define _M_FEATURE_ARC4RANDOM

#ifdef _M_FEATURE_ARC4RANDOM
#define RAND_SEED (arc4random())
#define RAND_IMPL (rand())
#else
#include <time.h>

#define RAND_SEED (time(NULL))
#define RAND_IMPL (rand())
#endif

#define _M_RANDOM_SET_SEED (srand( RAND_SEED ));

namespace shatter { namespace random {
static bool randomIsSeeded = false;

int random(int min, int max){
if(!randomIsSeeded){
_M_RANDOM_SET_SEED;
randomIsSeeded = true;
}

return (
(RAND_IMPL %
(max - min)
) + min
);
}

int d(int num, int sides){
int ttl = 0;
for(int di = 0;di < num;di++)
ttl += random(1, sides);

return ttl;
}

template <class T>
T randomFromSet(std::map<T, int> probs_keys){
int total_prob = 0;

/* HERE BE DRAGONS! */
typedef typename std::map<T, int>::iterator __local__iterator;

for(__local__iterator tprob_iter = probs_keys.begin();
tprob_iter != probs_keys.end();
++tprob_iter) {
total_prob += tprob_iter->last;
}

int target = random(0, total_prob);

for(__local__iterator targp_iter = probs_keys.begin();
targp_iter != probs_keys.end();
++targp_iter){
if(target < targp_iter->last){
return targp_iter->first;
}
}
}
} }

#undef _M_RANDOM_SET_SEED
#undef RAND_SEED
#undef RAND_IMPL

shatter/random/random.h:

#include <stdlib.h>
#include <map>

namespace shatter { namespace random {

/**
* min <= random(min, max) < max
*/
int random(int min, int max);

/**
* num <= d(num, sides) <= (num * sides)
*/
int d(int num, int sides);

template <class T>
T randomFromSet(std::map<T, int>);
} }

我用 clang++ -g -std=c++11 -c 编译上面的文件。出于某种原因,除了 randomFromSet() 之外,所有定义的符号都被放入目标文件。

$ nm build/random/random.o
00000000000007a0 s EH_frame0
0000000000000050 T __ZN7shatter6random1dEii
0000000000000000 T __ZN7shatter6random6randomEii
0000000000000808 b __ZN7shatter6randomL14randomIsSeededE
U _arc4random
U _rand
U _srand

randomFromSet() 从以下函数调用:

void Map::randomize(std::map<TileType, int> possibilities, int x, int y, int w, int h){
this->enforceBounds(&x, &y);
this->enforceBounds(&w, &h);

for(int yi = y;yi < h;yi++){
for(int xi = x;xi < w;xi++){
int tmp_type = shatter::random::randomFromSet<TileType>(possibilities);

this->tileMap[yi][xi]->type = (TileType) tmp_type;
}
}
}

另外:整体编译时:

Undefined symbols for architecture x86_64:
"shatter::dungeon::TileType shatter::random::randomFromSet<shatter::dungeon::TileType>(std::__1::map<shatter::dungeon::TileType, int, std::__1::less<shatter::dungeon::TileType>, std::__1::allocator<std::__1::pair<shatter::dungeon::TileType const, int> > >)", referenced from:
shatter::dungeon::Map::randomize(std::__1::map<shatter::dungeon::TileType, int, std::__1::less<shatter::dungeon::TileType>, std::__1::allocator<std::__1::pair<shatter::dungeon::TileType const, int> > >, int, int, int, int) in map.o

如果有人能告诉我 randomFromSet 没有出现在目标文件中的原因,我将不胜感激。

提前致谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com