简体   繁体   English

在Visual Studio 2017中的errno上获取链接错误lnk2001

[英]Getting a link error lnk2001 on errno in Visual Studio 2017

I have some C code that's compiled in every version of Visual Studio until I upgraded to 2017. For some reason, the upgrade process broke my linker references which resulted in over 400 link errors for things like HWND, SendMessage etc. 在升级到2017年之前,我已经在每个版本的Visual Studio中编译了一些C代码。由于某种原因,升级过程破坏了我的链接器引用,这导致了400多个链接错误,如HWND,SendMessage等。

I slogged through the linker properties input list and added user32.lib, gdi32.lib and a few others to resolve most of the missing external symbol errors but can't get rid of the last 2 errors. 我遍历了链接器属性输入列表,并添加了user32.lib,gdi32.lib和其他几个命令来解决大多数丢失的外部符号错误,但无法摆脱最后两个错误。 Both of them are looking for _errno which old C folks will recognize as a file system error result variable. 他们俩都在寻找_errno,旧的C程序员会认出_errno为文件系统错误结果变量。 I explicitly added libcmtd.lib to my linker input list and still no joy. 我将libcmtd.lib显式添加到链接器输入列表中,仍然没有任何乐趣。

How do I get around this last link error in VS2017? 如何解决VS2017中的最后一个链接错误?

The answer turned out to be that VS2017 altered the errno.h file to also declare errno. 答案是VS2017将errno.h文件更改为也声明了errno。 In past Visual Studio implementations, errno.h was just a list of defines for the various return values of errno. 在过去的Visual Studio实现中,errno.h只是errno的各种返回值的定义的列表。 In VS2017, errno.h conditionally declares errno. 在VS2017中,errno.h有条件地声明errno。

My file that made an extern reference to errno only cared if errno was zero or not so I didn't bother including errno.h in the file. 我的外部引用errno的文件仅在errno为零或不为零时才在意,因此我不必费心在文件中包含errno.h。

All that was required was to include errno.h in the file that was making an extern reference to errno. 所需要做的只是在外部引用errno的文件中包含errno.h。

The change in VS2017 makes sense so it's a bit odd it wasn't done much earlier. VS2017中的更改是有道理的,因此它没有更早完成就有些奇怪。

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

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