lsrawat
lsrawat

Reputation: 157

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).

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 .

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. I don't know why.

I have used all the includes that were used in file def.cpp in abc.cpp but same error.

When I am removing the sprintf() calls from abc.cpp then also all works fine.

Please if anyone can suggest why this is happening. Thanks

Upvotes: 1

Views: 581

Answers (1)

marcinj
marcinj

Reputation: 49976

I have searched msdn and also VS2015 and VS2005 source code folders and found no definition or declaration of Vsnprintf16.

I have not used eastl but it looks like you should define this function by yourself, you can find examples in following links:

https://github.com/BSVino/Digitanks/blob/master/common/eastl.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
}

Upvotes: 2

Related Questions