我尝试过查看类似的问题,但无法轻易找到对我的问题有帮助的问题。
我已经用 C++ 创建了一个项目,并且正在 UNIX 上编译、链接和运行它。我的具体问题是对我在单独文件中声明的方法的未定义引用。
在文件 SharedCache.cpp 中,我有以下方法:
int SharedCache::replaceLine(ullong address){
int evictPID = -1;
int cacheSet = calcCacheSet( address );
//random uniformly-distributed value for cache line
float numLines = static_cast<float>(CACHE_LINES_PER_SET);
uint cacheLine = static_cast<uint>(uniformDistr( numLines ));
if(cache[cacheSet][cacheLine] != NULL){
evictPID = cache[cacheSet][cacheLine]->PID;
}
uint PID= calcPID(address);
uint tag= calcTag(address);
cache[cacheSet][cacheLine]->setLine(PID, tag); //mutex method
return PID;
}
该行uint cacheLine = static_cast<uint>( uniformDistr( numLines ));
从另一个文件调用我想使用的函数。链接器错误是对此方法的未定义引用。
均匀分布(浮动);在头文件distributions.h 中声明并在distributions.cpp 中定义。在我的项目选项中,我设置了链接器标志 -distributions 并且我还编译了 distributions.cpp 以确保存在可以链接的 distributions.o 文件。
从这里开始,我不知道该去哪里,因为这并没有解决问题。