midl 找不到 C 预处理器 cl.exe

midl cannot find C preprocessor cl.exe

我正在尝试用 midl 编译我的 arith.idl 文件。我是运行windows7亲

这是我在 powershell 提示符下启动的命令:

PS> 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\midl.exe' .\arith.idl

Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
Copyright (c) Microsoft Corporation. All rights reserved.
64 bit Processing .\arith.idl
midl : command line error MIDL1005 : cannot find C preprocessor cl.exe
PS>

我在 windows RPC 编程方面相当菜鸟,非常感谢您的帮助。我已阅读 this 但这并不能解决任何问题(相同的症状)。我还尝试使用此命令指定预处理器 cl.exe:

PS C:\> & 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\midl.exe' /cpp_cmd 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe' C:\Users$e\Desktop\MIDL\arith.idl

Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
Copyright (c) Microsoft Corporation. All rights reserved.
Processing C:\Users\philippe.CHIBOLLO\Desktop\MIDL\arith.idl
PS C:\>

这个命令不return任何东西并且

echo $?

returns 假

编辑:

vcvarsall.bat 文件的执行不会改变任何东西。这是我启动的 powershell 命令的输出:

PS C:\> & 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat'
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
PS C:\> & 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\midl.exe' /cpp_cmd 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe' C:\Users$me\Desktop\MIDL\arith.idl
Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
Copyright (c) Microsoft Corporation. All rights reserved.
Processing C:\Users$me\Desktop\MIDL\arith.idl
PS C:\> echo $?
False
PS C:\>

不久前我写了一篇关于这个的文章。当您从 PowerShell 运行 Cmd.exe shell 脚本(批处理文件)时,环境变量更改不会传播到父进程 (PowerShell)。要解决此问题,您需要在 shell 脚本完成后捕获环境变量更改。这篇文章是:

IT Pro Today: Take Charge of Environment Variables in PowerShell

您可以使用该文章中的 Invoke-CmdScript 函数 运行 vcvarsall.bat 并将其环境变量更改传播到 PowerShell。

Invoke-CmdScript 看起来像这样:

function Invoke-CmdScript {
  param(
    [String] $scriptName
  )
  $cmdLine = """$scriptName"" $args & set"
  & $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
  select-string '^([^=]*)=(.*)$' | foreach-object {
    $varName = $_.Matches[0].Groups[1].Value
    $varValue = $_.Matches[0].Groups[2].Value
    set-item Env:$varName $varValue
  }
}

如果您想本地化 PowerShell 脚本中的环境变量更改,您还可以使用该文章中的 Get-Environment 和 Restore-Environment 函数。