Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

windows - midl cannot find C preprocessor cl.exe

I am trying to compile my arith.idl file with midl. I am running windows 7 pro.

Here is the command I launch in a powershell prompt:

PS> 'C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinmidl.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>

I am quite a noob at windows RPC programming, I would highly appreciate some help. I have read this but this does not resolve anything (same symptoms). I have also tried specifying the preprocessor cl.exe with this command:

PS C:> & 'C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinmidl.exe' /cpp_cmd 'C:Program Files (x86)Microsoft Visual Studio 10.0VCincl.exe' C:Users$eDesktopMIDLarith.idl

Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
Copyright (c) Microsoft Corporation. All rights reserved.
Processing C:Usersphilippe.CHIBOLLODesktopMIDLarith.idl
PS C:>

This command does not return anything and

echo $?

returns False

EDIT:

The execution of the vcvarsall.bat file does not change anything. Here is the output of the powershell command I launched:

PS C:> & 'C:Program Files (x86)Microsoft Visual Studio 10.0VCvcvarsall.bat'
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
PS C:> & 'C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinmidl.exe' /cpp_cmd 'C:Program Files (x86)Microsoft Visual Studio 10.0VCincl.exe' C:Users$meDesktopMIDLarith.idl
Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
Copyright (c) Microsoft Corporation. All rights reserved.
Processing C:Users$meDesktopMIDLarith.idl
PS C:> echo $?
False
PS C:>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I wrote an article about this not too long ago. When you run a Cmd.exe shell script (batch file) from PowerShell, environment variable changes do not propagate to the parent process (PowerShell). To work around this, you need to capture the environment variable changes after the shell script completes. The article is this one:

IT Pro Today: Take Charge of Environment Variables in PowerShell

You can use the Invoke-CmdScript function from that article to run vcvarsall.bat and propagate its environment variable changes to PowerShell.

Invoke-CmdScript looks like this:

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

You can also use the Get-Environment and Restore-Environment functions from that article if you want to localize the environment variable changes in your PowerShell script.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...