【问题标题】:Visual Studio 2012 alongside 2010 - kernel32.lib, windows.hVisual Studio 2012 和 2010 - kernel32.lib、windows.h
【发布时间】:2012-11-17 01:25:12
【问题描述】:

我刚刚将 Visual Studio 2012 与 Visual Studio 2010 一起安装。问题是我无法将简单项目从 2010 转换为 2012 - 它们无法链接到 kernel32.lib 等文件或包含 windows 等文件。 H。我的系统还安装了 Windows SDK 7.1。

我尝试在我的 x86 和 x64 用户平台上使用 Property Manager(因为我在那里添加了适当的 $(DXSDK_DIR) 引用),但结果好坏参半 - 有时它可以正常工作,有时它可以编译但不链接,其他时候它只是停在 windows.h

例如,目前我正在获取

1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'

1>Source.cpp(2): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

(取决于是否包含“windows.h”)仅在 x64 中具有简单的“hello world”类型程序。

Active(Debug) / Active(x64) -> VC++ Directories -> Include Directories 的项目属性中,我现在可以看到$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include。如果我展开该输入框并单击“编辑”,我会看到:

$(VCInstallDir) = C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\
$(WindowsSDK_IncludePath) = c:\Program Files (x86)\Windows Kits\8.0\Include\um;c:\Program Files (x86)\Windows Kits\8.0\Include\shared;c:\Program Files (x86)\Windows Kits\8.0\Include\WinRT

虽然我的平台工具集 v110 windows.h 位于 c:\Program Files (x86)\Windows Kits\8.0\Include\um\Windows.h(所以应该没有问题)。如果我选择 Windows SDK 7.1 作为平台工具集,则一切正常。

除了格式化和重装Windows还有什么办法吗?

L.E.如果我用系统内的绝对路径替换 $(variable) 目录,一切正常。我不明白我为什么要这样做,因为我也在与其他人分享这个项目。

【问题讨论】:

    标签: c++ visual-studio-2010 visual-studio-2012


    【解决方案1】:

    我知道上面几乎有答案。但是……

    问题似乎是在安装VS2012和VS2010时,VS2012的配置无法正常工作。

    修复方法是编辑 %home%\AppData\Local\Microsoft\MSBuild\v4.0 中的 props 文件。

    这些是对我有用的文件,使用 SDK v8.1。

    第一个用于 32 位构建的 Microsoft.Cpp.Win32.user.props:

    <?xml version="1.0" encoding="utf-8"?> 
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <IncludePath>C:\Program Files (x86)\Windows Kits\8.1\include\um;C:\Program Files (x86)\Windows Kits\8.1\include\shared;C:\Program Files (x86)\Windows Kits\8.1\include\winrt;$(IncludePath)</IncludePath>
        <LibraryPath>C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86;$(LibraryPath)</LibraryPath>
        <ExecutablePath>C:\Program Files (x86)\Windows Kits\8.1\bin\x86;$(ExecutablePath)</ExecutablePath>
      </PropertyGroup>
    </Project>
    

    现在 Microsoft.Cpp.x64.user.props 用于 64 位构建:

    <?xml version="1.0" encoding="utf-8"?> 
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <IncludePath>C:\Program Files (x86)\Windows Kits\8.1\include\um;C:\Program Files (x86)\Windows Kits\8.1\include\shared;C:\Program Files (x86)\Windows Kits\8.1\include\winrt;$(IncludePath)</IncludePath>
        <LibraryPath>C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64;$(LibraryPath)</LibraryPath>
        <ExecutablePath>C:\Program Files (x86)\Windows Kits\8.1\bin\x64;$(ExecutablePath)</ExecutablePath>
      </PropertyGroup>
    </Project>
    

    我希望这可以帮助其他人解决这个问题,我还没有在其他任何地方找到解决方案。

    【讨论】:

    • 似乎是合法的,我会尽快从 Win 7 切换到 Win 8.1,我将与 VS 2010、2012 和 2013 一起测试并在此处发布结果。
    • 这对我有用,但对于 x64,我必须将 ExecutablePath 更改为 x86 分支。否则 rc.exe(x64 版本)会给我一个“操作标识符无效”。错误。为了确定,我还添加了 x86
    • 它也对我有用。我的*.props 几乎是空的!只有一条路径,来自 Visual Leak Detector!但我不知道这些文件发生了什么。我唯一记得的是我上周安装了 Windows 10 Kit SDK。
    • 太棒了,它有帮助!我浪费了很多时间才找到你的帖子。
    【解决方案2】:

    我遇到了类似的问题。
    就我而言,这是因为项目设置中没有继承正确的路径。

    检查路径是否继承于:项目 -> 属性 -> VC++ 目录
    包含库目录下,转到编辑

    确保选中Inherit from parent or project defaults

    VS2012 默认属性和宏设置正确。 (虽然我遇到了常见的安装问题,我不得不替换所有的 VC 目录,因为它甚至没有安装 C++ 核心库)

    【讨论】:

      猜你喜欢
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2017-06-12
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多