0

I am porting a legacy app (originally compiled with VC 6.0) to MSVC 2019. It uses a legacy static library (libtest.lib), compiled with VC 6.0. My problem is that some (but not all) standard libc functions in libtest.lib are not being resolved by MSVC 2019.

For example, libtest.lib uses vsprintf(). On compilation MSVC 2019 reports "unresolved external symbol _vsprintf referenced in ...". Other libc functions (e.g. strlen) are resolved just fine.

I've tried mucking with a gazillion build settings with no joy.
Why is this happening and how can I fix it?

My research so far...

I did a lot of digging in the VC60 headers and found that vsprintf is defined in studio.h as

_CRTIMP int __cdecl vsprintf(char *,const char *, va_list);

while strlen in defined in string.h as

size_t  __cdecl strlen(const char *); 

I'm not sure of the implications but I'm guessing that strlen is just a plain-vanilla static function while vsprintf is imported from some CRT DLL (which is probably different in MSVC 2019).

I guess I could port libtest.lib to MSVC 2019 too, but I've got close to 100 other static libraries and porting them all would be a major pain in the butt.

DontPanic
  • 2,164
  • 5
  • 29
  • 56
  • 1
    Does this answer your question? [Unresolved external symbol \_\_vsnprintf .... (in dxerr.lib)?](https://stackoverflow.com/questions/31053670/unresolved-external-symbol-vsnprintf-in-dxerr-lib) – dewaffled May 16 '20 at 16:46
  • Wow, what a magic bullet! WORKED PERFECTLY! Thanks. – DontPanic May 16 '20 at 17:37
  • Dewaffled:. Post this as an answer and I will accept it and get you some SO brownie points :) – DontPanic May 16 '20 at 20:28

1 Answers1

1

Thanks to @dewaffled for this great answer:
Microsoft has a library to adapt CRT functions to the latest versions of MSVC e.g., 2019

Simply add the following line to your main program:

#pragma comment(lib, "legacy_stdio_definitions.lib")

Alternatively, I think you can add the library to:

Project Properties -> Linker -> Input -> Additional Dependencies  
DontPanic
  • 2,164
  • 5
  • 29
  • 56