开发者

How to access the ProgramFiles environment variable from nmake on x64 machines?

I try to get the path to the ProgramFiles environmental variable, that is supposed to expand to C:\Program Files (x86) on a x64 machine and to C:\Program Files on a x86 machine.

The problems is that in the nmake file if I do:

 all:
      echo $(PROGRAMFILES)

This will expand to C:\Program Files everytime and this is wrong.

Environment details from a x64 machine:

ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\开发者_开发问答Program Files

:: this one is special, if will return different results based on current process x86/x64
ProgramFiles=C:\Program Files (x86) or C:\Program Files
PROCESSOR_ARCHITECTURE=x86 or x64

Now the updated question is how to get the location of x86 program files inside nmake, in a way this will work on both x86 and x64 machines?


This expression seems to work on 64-bit Windows 7, with nmake running in both 32-bit and 64-bit:

%%PROGRAMFILES(x86)%%

e.g.

LC = %%PROGRAMFILES(x86)%%\Microsoft SDKs\Windows\v7.0A\bin\lc.exe


If you're on an x64 machine it is totally legal that %ProgramFiles% points to C:\Program Files - from within a 64-bit program's environment. The variable you have to use to get the x86 counterpart is %ProgramFiles(x86)%.

Which one to use can be determined by evaluating the current OS's architecture that is set in the PROCESSOR_ARCHITECTURE environment variable (which is e.g. set to AMD64). Or simply try to get %ProgramFiles(x86)% and if it is empty get the content of %ProgramFiles%.

Another approach would be to start a 32-bit cmd.exe and run your make there. It is located in C:\Windows\SysWOW64.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜