windows Visual Studio 2010 express + win sdk = 无法打开输入文件“kernel32.lib”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9821700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:22:51  来源:igfitidea点击:

visual studio 2010 express + win sdk = cannot open input file 'kernel32.lib'

windowsvisual-c++64-bitlinker-errors

提问by pawel

I used to compile for x64 using VS2008 express and win SDK. Recently rebuilt my machine (upgraded to 64bit Windows 7) and got latest express installed. Followed the same procedure to allow x64 targets and my sources don't link any more. no matter what I do I always get:

我曾经使用 VS2008 express 和 win SDK 为 x64 编译。最近重建了我的机器(升级到 64 位 Windows 7)并安装了最新的 Express。遵循相同的程序以允许 x64 目标并且我的源不再链接。无论我做什么,我总是得到:

LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'

链接:致命错误 LNK1181:无法打开输入文件“kernel32.lib”

funny enough 32bit compilation works fine.

足够有趣的 32 位编译工作正常。

Is this some well know problem? Google didn't give me any clues how to tackle it just a couple of mentions of the same problem but no solutions.

这是一些众所周知的问题吗?谷歌没有给我任何线索如何解决它只是提到了同样的问题,但没有解决方案。

Is it possible to use VS 2010 with win 7 SDK to target 64bit?

是否可以将 VS 2010 与 win 7 SDK 一起用于 64 位?

thanks Pawel

谢谢帕维尔

回答by pawel

the solution was dead easy at the end. The trick is to point VS to win SDK that for some reason was incorrect in my case. Project Properties -> VC++ Directories -> Library Directoriesshould point to C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64

最后的解决方案很简单。诀窍是让 VS 赢得 SDK,因为某些原因在我的情况下是不正确的。 Project Properties -> VC++ Directories -> Library Directories应该指向C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64

回答by Michael Litvin

Something else I found, also dead easy, is to go to Project Properties->General and set Platform Toolset to Windows7.1SDK. Wonder why this works...

我发现的其他东西也很简单,就是转到项目属性->常规并将平台工具集设置为 Windows7.1SDK。想知道为什么这有效...

回答by Eric Omine

I've had the same problem and the answers here helped me, but I had to do more things.

我遇到了同样的问题,这里的答案对我有帮助,但我必须做更多的事情。

Something had corrupted my Windows SDK installation, so I was missing all .lib files that go into C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\ (the x64 folder inside was ok). So I followed what's been said hereand reinstalled it. Than I could set Platform Toolset to Windows7.1SDK (in both VS2010 and VS2013).

某些东西损坏了我的 Windows SDK 安装,所以我丢失了进入 C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\ 的所有 .lib 文件(里面的 x64 文件夹没问题)。所以我按照这里所说的重新安装它。比我可以将平台工具集设置为 Windows7.1SDK(在 VS2010 和 VS2013 中)。

This works because the Platform Toolset changes the $(WindowsSdkDir) path within Visual Studio (those paths saved are in the system registry), which were broken if Kernel32.lib isn't found.

这是有效的,因为平台工具集更改了 Visual Studio 中的 $(WindowsSdkDir) 路径(保存的路径在系统注册表中),如果未找到 Kernel32.lib,则该路径会损坏。

回答by TrophyGeek

If none of the above solutions worked. Stop and do a sanity check. I got burned using the wrong -Gconfig string and it gave me this misleading error.

如果上述解决方案均无效。停下来做一个健全的检查。我使用错误的-G配置字符串被烧毁,它给了我这个误导性错误。

First, run from the VS Command Prompt notthe regular command prompt. You can find it in Start Menu -> Visual Studio 2015 -> MSBuild Command Prompt for VS2015

首先,从 VS 命令提示符而不是常规命令提示符运行。你可以在 Start Menu -> Visual Studio 2015 -> MSBuild Command Prompt for VS2015

This sets up all the correct paths to VS tools, etc.

这将设置 VS 工具等的所有正确路径。

Now see what generators are available from cmake...

现在看看 cmake 有哪些可用的生成器...

cmake -help

cmake -help

...<snip>... The following generators are available on this platform: Visual Studio 15 [arch] = Generates Visual Studio 15 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". ...

...<snip>... The following generators are available on this platform: Visual Studio 15 [arch] = Generates Visual Studio 15 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". ...

Then chose the appropriate string withthe arch added.

然后选择相应的字符串添加的牌坊。

mkdir _build cd _build cmake .. -G "Visual Studio 15 Win64"

mkdir _build cd _build cmake .. -G "Visual Studio 15 Win64"

Running cmake in a subdirectory makes it easier to do a 'clean' since you can just delete everything in that directory.

在子目录中运行 cmake 可以更轻松地进行“清理”,因为您可以删除该目录中的所有内容。

I upgraded to Visual Studio 15 but wasn't paying attention and was trying to generate for 2012.

我升级到 Visual Studio 15 但没有注意并试图为 2012 生成。

回答by DarthGizka

FWIW, I had the same problem with Visual Studio 2013 when the entire v8.1 SDK install (files + reg keys) went AWOL, probably caused by the installation of Emborlandero RAD Studio.

FWIW,当整个 v8.1 SDK 安装(文件 + reg 密钥)无法正常运行时,我在 Visual Studio 2013 上遇到了同样的问题,这可能是由于安装了 Emborlandero RAD Studio 引起的。

Setting the WindowsSdkDirenvironment variable had no effect since both Studio itself (devenv.exe, environment inspected via Process Explorer) and a batch file called from a batch file called from vcvarsall.bateffectively erased that variable because they couldn't find the v8.1 SDK.

设置WindowsSdkDir环境变量没有任何影响,因为 Studio 本身(devenv.exe通过 Process Explorer 检查环境)和从调用的批处理文件调用的批处理文件vcvarsall.bat有效地擦除了该变量,因为他们找不到 v8.1 SDK。

Visual Studio doesn't allow machine-specific directories to be configured in a machine-wide way (the suggestion to put this machine dependency into each and every project file is ludicrous beyond belief) and re-installing the v8.1 SDK was not possible in a timely fashion. A quick fix to get Studio working again in the meantime was to add the string value InstallationFolderunder

Visual Studio 不允许以机器范围的方式配置特定于机器的目录(将这个机器依赖项放入每个项目文件的建议是荒谬的,难以置信)并且重新安装 v8.1 SDK 是不可能的及时。速战速决得到工作室在此期间再次合作是添加字符串值InstallationFolder

Software/Microsoft/Microsoft SDKs/Windows/v8.1/

with the same contents as its v8.0 cousin. This was under HKLM/Wow6432Nodebut plain HKLMor HKCUshould work as well.

与它的 v8.0 表亲相同的内容。这很HKLM/Wow6432Node简单,HKLM或者也HKCU应该有效。

That got Studio working again immediately, without even a restart.

这让 Studio 立即再次工作,甚至没有重新启动。