简体   繁体   中英

Compilation error while using VS 2005 library in VC6

I have a library which is compiled in VS 2005 and I am trying to link it with one of the old VC 6 workspace, while linking I am getting following errors.

error LNK2001: unresolved external symbol _sprintf_s
error LNK2001: unresolved external symbol _strncpy_s
error LNK2001: unresolved external symbol _strcpy_s    
error LNK2001: unresolved external symbol _strcat_s    
error LNK2001: unresolved external symbol __time64    
unresolved external symbol __alloca_probe_16    
unresolved external symbol _main    
fatal error LNK1120: 7 unresolved externals    
Error executing link.exe.

Please help me in getting away with this error.

_strcpy_s is not defined in the VC6 libraries, it was added in VS2005 (or maybe VS2002/2003 ?). I don't think there's a way around it.

AFAIK, it's not usual to use a library from an earlier version of the compiler with an older version of the compiler.

I assume the above is a result of you statically linking the executable?

The _s functions are "safe" functions that Microsoft added to the runtime library to make it harder to write code with buffer overflows. They were added after VC6 (either in VS.NET or VS2003) and the functions are not present in the VC6 runtime libraries, so that is why your link is failing. The only two ways to get around this are either to build the whole set of binaries with VS2005 or with VC6. The latter is probably not a good idea as it would require you reworking the library to use the standard C functions instead.

It is generally not a good idea to mix compiler versions in static libraries and executables as the runtime libraries do change and you're left with problems like these.

You could turn your library into a DLL, but that's opening another can of worms...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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