midl cannot find C preprocessor cl.exe

本小妞迷上赌 提交于 2019-11-28 09:41:58

问题


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 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>

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

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

回答1:


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:

Windows IT Pro: 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: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
  }
}

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.



来源:https://stackoverflow.com/questions/28701561/midl-cannot-find-c-preprocessor-cl-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!