简体   繁体   English

在VC6中使用VS 2005库时出现编译错误

[英]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. 我有一个在VS 2005中编译的库,我试图将其与旧的VC 6工作区之一链接,而链接时出现以下错误。

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 ?). VC6库中未定义_strcpy_s ,它是在VS2005(或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. AFAIK,通常不使用早期版本的编译器和早期版本的库。

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. _s函数是Microsoft添加到运行时库中的“安全”函数,以使其更难编写带有缓冲区溢出的代码。 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. 它们是在VC6之后添加的(在VS.NET或VS2003中),而这些功能在VC6运行时库中不存在,因此这就是链接失败的原因。 The only two ways to get around this are either to build the whole set of binaries with VS2005 or with VC6. 解决此问题的唯一两种方法是使用VS2005或VC6构建整套二进制文件。 The latter is probably not a good idea as it would require you reworking the library to use the standard C functions instead. 后者可能不是一个好主意,因为它将要求您重新编写库以使用标准C函数。

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... 您可以将您的库转换为DLL,但这会打开另一罐蠕虫……

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

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