2012-05-07 2 views
0

섹션 내에서 매크로를 여러 번 호출합니다. 매크로는 디렉토리가 존재하는지 여부를 검사합니다.섹션에서 매크로를 두 번 이상 사용하십시오.

내 문제점 : 섹션 내부에서이 매크로를 두 번 이상 호출하기 때문에 오류가 발생합니다. 컴파일 오류를 어떻게 해결할 수 있습니까?

오류 : "오류 : 라벨"CreateDirThenInstall : "이미 섹션에서 선언"

당신은 내가 섹션에 한 번이 매크로보다 더 사용할 수있는 방법을 말해 줄래?

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 

답변

1

문제는 매크로가 아니라 레이블입니다. 섹션에서 정확히 동일한 레이블을 두 번 사용했으나 가능하지 않습니다.

매크로에서 레이블을 고유하게 만들 수 있습니다 (매크로를 두 번 이상 삽입 한 경우에도 마찬가지 임). 컴파일 시간 명령 ${__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 

그러나 위의 경우는 필요하지 않습니다. SetOutPath 명령은 필요한 경우 디렉토리를 만듭니다. 문서에서 :

Sets the output path ($OUTDIR) and creates it (recursively if necessary), if it does not exist.

당신이 (제거하는 동안 그것을 사용하는, 예를 어딘가에 그것을 쓰기) 생성에 대한 모든 디렉토리를 알 필요가없는 경우 그래서, 당신은 전혀 할 필요가 없습니다.

관련 문제