0

I am working on some legacy code that I am not too familiar with. I encountered an error when I recompiled my project in visual studio 2015 from visual studio 2012.

I am having reference errors to function "_getts", which is normally part of "tchar.h".

enter image description here

I compared my visual studio 2012 installation to my 2015 installation and I see that the header file "tchar.h" is no longer in the shipping install. After further research, I see that Microsoft released the "Universal CRT" that now includes some of those header files that I see were removed from 2015. In the Microsoft documentation, I see that Visual Studio 2015 still clearly references "tchar.h".

I figure this is something so simple that I am clearly overlooking. If there is any good documentation that I missed also please do provide.

Thanks

  • gets() has been removed from the C11 and C++11 standards, its built-in buffer overflow bug made it entirely too dangerous. You'll need to move to `_getts_s()`, it takes an extra argument that specifies the buffer size. – Hans Passant Feb 03 '16 at 16:01
  • Perfect. Thanks for the information! – user3596611 Feb 03 '16 at 16:17

2 Answers2

0

_getts is just a macro definition, that's why the linker can't find it. Try defining the macro before main():

#define _getts _getws
Eldar Dordzhiev
  • 5,105
  • 2
  • 22
  • 26
  • That worked for me to get rid of the error. Just out of curiousity, I was wondering why running with the vs 14.0 toolset would cause the error but the vs 11.0 toolset it would not give me the compile error? Also, I just saw that "tchar.h" got moved into the Windows Universal CRT so that answers another one of my questions. – user3596611 Feb 03 '16 at 15:56
  • @user3596611 The v140 might have some breaking changes (especially as they introduced the Univesal CRT), but I'm pretty sure that they wouldn't dare to remove `TCHAR`. Probably a bug or something else, I can't judge without the code. If my answer helped you please mark it as the answer. – Eldar Dordzhiev Feb 03 '16 at 21:12
  • I forgot to update this thread, but this issue was the result of the breaking changes with the Universal CRT. I had to do some reading and get caught up with the changes for v140. – user3596611 Apr 19 '16 at 15:18
0

The _getts macro used to resolve to either gets (ANSI) or _getws (Unicode) depending of the charset setting. Both functions have been retired in VC++ 2015, along with the macro itself.

From Breaking Changes in Visual C++ 2015:

The gets and _getws functions have been removed. The gets function was removed from the C Standard Library in C11 because it cannot be used securely. The _getws function was a Microsoft extension that was equivalent to gets but for wide strings. As alternatives to these functions, consider use of fgets, fgetws, gets_s, and _getws_s.

dxiv
  • 16,984
  • 2
  • 27
  • 49