3

arith.idl ファイルを midl でコンパイルしようとしています。Windows 7 pro を実行しています。

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 シェル スクリプト (バッチ ファイル) を実行すると、環境変数の変更が親プロセス (PowerShell) に反映されません。これを回避するには、シェル スクリプトの完了後に環境変数の変更をキャプチャする必要があります。記事はこれです:

今日の 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 に答える