3

我正在尝试用 midl 编译我的 arith.idl 文件。我正在运行 Windows 7 专业版。

这是我在 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 编程的菜鸟,非常感谢一些帮助。我已阅读内容,但这并不能解决任何问题(相同的症状)。我还尝试使用以下命令指定预处理器 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:\>

此命令不返回任何内容,并且

echo $?

返回 False

编辑:

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:\>
4

1 回答 1

5

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

今日 IT 专业人士:在 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 函数。

于 2015-02-27T21:48:25.367 回答