Installation 在节中多次使用宏
我在一个区段内多次调用宏。宏检查目录是否存在,如果不存在,则创建该目录 我的问题:我收到一个错误,因为我在一个分区内多次调用此宏。如何修复编译错误 错误:“错误:标签”CreateDirThenInstall:“已在节中声明” 你能告诉我如何在一个部分中多次使用这个宏吗Installation 在节中多次使用宏,installation,nsis,Installation,Nsis,我在一个区段内多次调用宏。宏检查目录是否存在,如果不存在,则创建该目录 我的问题:我收到一个错误,因为我在一个分区内多次调用此宏。如何修复编译错误 错误:“错误:标签”CreateDirThenInstall:“已在节中声明” 你能告诉我如何在一个部分中多次使用这个宏吗 Section "Install Plugin Files" MainSetup !insertmacro ValidateDir "c:/blah" setOutPath "c:/blah" file "C:/bl
Section "Install Plugin Files" MainSetup
!insertmacro ValidateDir "c:/blah"
setOutPath "c:/blah"
file "C:/blah/a.txt"
file "C:/blah/b.txt"
!insertmacro ValidateDir "c:/other"
setOutPath "c:/other"
file "c:/other/a.txt"
file "c:/other/b.txt"
sectionend
!macro ValidateDir dir
IfFileExists "$dir" ExitMacro CreateDirThenInstall
CreateDirThenInstall: # Error here: Error: label "CreateDirThenInstall:" already declared in section
createDirectory "${dir}"
ExitMacro:
!macroend
问题在于标签,而不是宏。 您在该部分中使用了两次完全相同的标签,这是不可能的 可以使宏中的标签唯一(即使宏多次插入)。编译时命令
${uuuuuuuu-LINE}
可用于此目的。然后你可以这样写:
!macro ValidateDir dir
!define UniqueId1 ${__LINE__}
!define UniqueId2 ${__LINE__}
IfFileExists "${dir}" Exit_${UniqueId1} CreateDir_${UniqueId2}
CreateDir_${UniqueId2}:
createDirectory "${dir}"
Exit_${UniqueId1}:
!undef UniqueId1
!undef UniqueId2
!macroend
但在你的情况下,我认为上述是没有必要的<代码>设置输出路径指令在必要时为您创建目录。从文件:
设置输出路径($OUTDIR)并创建它(如果
必要),如果不存在
因此,如果您不需要了解创建的每个目录(并将其写入某个位置,例如在卸载过程中使用它),那么您根本不需要这样做