简体   繁体   English

在Visual Studio 2013上的C ++中链接错误

[英]Linking Error in C++ on visual studio 2013

Following error is coming when I am compiling the project "proj1" code which is using xyz.lib (it is a different project that got compiled successfully). 当我使用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 has calls to function sprintf . abc.cpp调用了sprintf函数。

When I am moving all the code of abc.h and abc.cpp to some other lets say def.h and def.cpp file which is already present in xyz project then all works fine, no linking error. 当我将abc.h和abc.cpp的所有代码移至其他代码时,可以说xyz项目中已经存在的def.h和def.cpp文件,然后一切正常,没有链接错误。 I don't know why. 我不知道为什么

I have used all the includes that were used in file def.cpp in abc.cpp but same error. 我已经使用了abc.cpp中的文件def.cpp中使用的所有包含项,但存在相同的错误。

When I am removing the sprintf() calls from abc.cpp then also all works fine. 当我从abc.cpp中删除sprintf()调用时,也一切正常。

Please if anyone can suggest why this is happening. 如果有人可以建议为什么会这样,请。 Thanks 谢谢

I have searched msdn and also VS2015 and VS2005 source code folders and found no definition or declaration of Vsnprintf16 . 我搜索了msdn以及VS2015和VS2005源代码文件夹,但未找到Vsnprintf16定义或声明。

I have not used eastl but it looks like you should define this function by yourself, you can find examples in following links: 我还没有使用过Eastl,但您似乎应该自己定义此函数,可以在以下链接中找到示例:

https://github.com/BSVino/Digitanks/blob/master/common/eastl.cpp https://github.com/BSVino/Digitanks/blob/master/common/eastl.cpp

https://github.com/electronicarts/EASTL/blob/master/test/source/main.cpp https://github.com/electronicarts/EASTL/blob/master/test/source/main.cpp

for reference I include it here: 供参考,我在这里包括:

// 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM