当我编译使用 xyz.lib 的项目“proj1”代码时出现以下错误(这是一个成功编译的不同项目)。
Error 3 error LNK2019: unresolved external symbol "int __cdecl Vsnprintf16(unsigned short *,unsigned int,unsigned short const *,char *)" (?Vsnprintf16@@YAHPAGIPBGPAD@Z) referenced in function "int __cdecl eastl::Vsnprintf(wchar_t *,unsigned int,wchar_t const *,char *)" (?Vsnprintf@eastl@@YAHPA_WIPB_WPAD@Z) File : xyz.lib(abc.obj)
abc.cpp 调用函数 sprintf 。
当我将 abc.h 和 abc.cpp 的所有代码移动到其他文件时,让我们说 def.h 和 def.cpp 文件,这些文件已经存在于 xyz 项目中,然后一切正常,没有链接错误。我不知道为什么。
我已经在 abc.cpp 中使用了文件 def.cpp 中使用的所有包含,但同样的错误。
当我从 abc.cpp 中删除 sprintf() 调用时,一切正常。
如果有人能提出为什么会这样,请告诉我。谢谢
最佳答案
我搜索了 msdn 以及 VS2015 和 VS2005 源代码文件夹,没有找到 Vsnprintf16
的定义或声明。
我没有用过eaSTL,但看起来你应该自己定义这个函数,你可以在以下链接中找到示例:
https://github.com/BSVino/Digitanks/blob/master/common/eastl.cpp
https://github.com/electronicarts/EASTL/blob/master/test/source/main.cpp
为了引用,我把它放在这里:
// EASTL also wants us to define this (see string.h line 197)
int Vsnprintf8(char* pDestination, size_t n, const char* pFormat, va_list arguments)
{
#ifdef _MSC_VER
return _vsnprintf(pDestination, n, pFormat, arguments);
#else
return vsnprintf(pDestination, n, pFormat, arguments);
#endif
}
int Vsnprintf16(char16_t* pDestination, size_t n, const char16_t* pFormat, va_list arguments)
{
#ifdef _MSC_VER
return _vsnwprintf((wchar_t*)pDestination, n, (wchar_t*)pFormat, arguments);
#else
char* d = new char[n+1];
int r = vsnprintf(d, n, convertstring<char16_t, char>(pFormat).c_str(), arguments);
memcpy(pDestination, convertstring<char, char16_t>(d).c_str(), (n+1)*sizeof(char16_t));
delete[] d;
return r;
#endif
}
关于c++ - visual studio 2013 中的 C++ 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37388220/