当我编译使用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的代码移动到其他一些时,让我们说xhz项目中已经存在的def.h和def.cpp文件然后一切正常,没有链接错误。我不知道为什么。
我已经使用了abc.cpp文件def.cpp中使用的所有包含但是同样的错误。
当我从abc.cpp删除sprintf()调用时,一切正常。
如果有人能说明为什么会这样,请。感谢
答案 0 :(得分:1)
我搜索过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
}