如何在 x64 机器上从 nmake 访问 ProgramFiles 环境变量?
我尝试获取 ProgramFiles
环境变量的路径,该变量应该扩展到 x64
上的 C:\Program Files (x86)
机和 x86
机器上的 C:\Program Files
。
问题是,在 nmake 文件中,如果我这样做:
all:
echo $(PROGRAMFILES)
这每次都会扩展到 C:\Program Files
,这是错误的。
x64 机器的环境详细信息:
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
现在更新的问题是如何获取 nmake 中 x86 程序文件的位置,以某种方式在 x86 和 x64 机器上都工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该表达式似乎适用于 64 位 Windows 7,
nmake
在 32 位和 64 位中运行:例如
This expression seems to work on 64-bit Windows 7, with
nmake
running in both 32-bit and 64-bit:e.g.
如果您使用的是 x64 计算机,则
%ProgramFiles%
指向C:\Program Files
是完全合法的 - 在 64 位程序环境中。用于获取 x86 对应项的变量是
%ProgramFiles(x86)%
。可以通过评估在
PROCESSOR_ARCHITECTURE
环境变量中设置的当前操作系统架构(例如设置为AMD64
)来确定使用哪一种。或者只是尝试获取%ProgramFiles(x86)%
,如果它为空,则获取%ProgramFiles%
的内容。另一种方法是启动 32 位
cmd.exe
并在那里运行您的 make。它位于C:\Windows\SysWOW64
。If you're on an x64 machine it is totally legal that
%ProgramFiles%
points toC:\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 toAMD64
). 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 inC:\Windows\SysWOW64
.