windows - 如何使用 NMake 设置环境变量

标签 windows makefile nmake

我正在使用 NMake 制作联编文件。我有一些实用程序可以运行以将一个文件转换为 CPP 文件。该实用程序需要在 session 期间设置特定的 Windows 环境变量。我可以在 Makefile 中设置这个变量,还是需要创建一个批处理脚本来在调用 NMake 之前设置变量?

最佳答案

使用 !if [set ...] trick :

!if [set myvar=1]
!endif

# Macro values are fine, too, of course:
MYVAL=preprocessed
!if [set myvar=$(MYVAL)]
!endif

# Proof that myvar has really become an env. var. (see the output):
myvar=This is propagated to the env now!
mymacro=(But this isn't, of course.)

# This handy form works, too:
!if [set myA=1] || [set myB=2]
!endif

# But this will *NOT* make myX an env. var., if it hasn't been set yet:
!if [set myX=$(myX)]
!endif
myX=So you'll not see this...

all:
    set my

输出:

D:\tmp>nmake -f test.mak

Microsoft (R) Program Maintenance Utility Version 14.21.27702.2
Copyright (C) Microsoft Corporation.  All rights reserved.

        set my
myA=1
myB=2
myvar=This is propagated to the env now!

关于windows - 如何使用 NMake 设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38381422/

相关文章:

c - 使用子目录中的程序集目标文件

c - 在 MakeFile 中使用调试器

windows - 使用 nmake.exe Windows 在 makefile 中无法识别 addprefix 命令

c++ - 在单独的文件夹中包含头文件

Windows 批处理文件启动带有按钮的 gui

c - 如何在 C 中获取 WAV 文件的持续时间?

perl - 如何使用 Makefile.PL 和 ExtUtils::MakeMaker 复制文件?

Linux 命令行更改 Windows 可执行程序集信息

windows - 在长模式下复制短 8.3 文件名 (Windows)

将 GhostPDL 编译为 DLL