我目前在我的程序中使用 vector ,但出现了一些奇怪的错误,这些错误是在我开始使用该类后才出现的。
错误是:
1>MyCloth.obj : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "public: unsigned int & __thiscall std::vector<unsigned int,class std::allocator<unsigned int> >::operator[](unsigned int)" (??A?$vector@IV?$allocator@I@std@@@std@@QAEAAII@Z)
1>libcpmtd.lib(stdthrow.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW
1>D:\Licenta\Project\IOPBTS\Debug\IOPBTS.exe : fatal error LNK1120: 1 unresolved externals
我的代码是:
在头文件中:
#undef vector
#include <vector>
void findPieceVertices(NxU32 selectedVertex);
bool checkVertexExistsInClothPieceElements(int vertex);
void findVertexTriangles(NxU32 vertex);
std::vector<NxU32> clothPieceElements;
在cpp文件中:
bool MyCloth::checkVertexExistsInClothPieceElements(int vertex)
{
for(int i=0;i<clothPieceElements.size();i++)
if(clothPieceElements[i]==vertex)
return true;
return false;
}
void MyCloth::findVertexTriangles(NxU32 vertex)
{
NxMeshData data = mCloth->getMeshData();
NxU32* vertices = (NxU32*)data.indicesBegin;
NxU32 aux = 0;
for(int i=0;i<(mInitNumVertices-1)*3;i+=3)
{
if(*vertices == vertex || *(vertices+1) == vertex || *(vertices+2) == vertex)
{
if(!checkVertexExistsInClothPieceElements(*vertices))
clothPieceElements.push_back(*vertices);
if(!checkVertexExistsInClothPieceElements(*(vertices+1)))
clothPieceElements.push_back(*(vertices+1));
if(!checkVertexExistsInClothPieceElements(*(vertices+2)))
clothPieceElements.push_back(*(vertices+2));
}
vertices = vertices + 3;
}
void MyCloth::findPieceVertices(NxU32 selectedVertex)
{
clothPieceElements.push_back(selectedVertex);
int i=0;
while(i<clothPieceElements.size())
{
findVertexTriangles(clothPieceElements[i]);
i++;
}
}
我做错了什么?我在网上找了个东西,说我用的文件是release模式编译的,我也应该这样做。问题是,如果我在 Release模式下编译,这些错误就会消失,但我的程序无法找到一个非常重要的非 C 库,该库由添加到 VCC 目录 -> 包含目录中的路径指向。
有谁知道为什么会出现这个错误?或者是什么意思
编辑:另外,谁能告诉我在 Debug模式或 Release模式下构建的区别?
最佳答案
您似乎把 CRT 库搞得一团糟。 Debug 和 Release 构建之间有两个主要区别:
- 使用不同的 CRT 库
- 对代码进行了不同的优化
两者都与您的问题有关。一、check this comment .看起来您的链接行中缺少 libcmtd.lib
。检查您是否没有从链接器 -> 输入选项下的链接中排除像这样的重要库。
__CrtDbgReportW
函数与 vector::operator[]
在调试构建中执行的一些运行时检查有关。由于这些检查在 Release 构建中被禁用,因此您在 Release 中不会出现此错误。
还要确保您在 C/C++ -> 代码生成选项下使用正确版本的 CRT。您应该有一个用于调试配置的调试版本(动态或静态)和一个用于发布配置的发布版本。
这是一个棘手的问题,没有任何经验就可以解决。如果有可能,我建议您从默认模板创建一个新项目,并将您的所有文件添加到这个新项目,以确保默认情况下所有设置都是正确的。
关于C++ vector 操作错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16734957/