Archive: Compiler is being wrong?


Compiler is being wrong?
Hello,

I wonder why this is. I am using some custom variables to store various values needed for the installer to make it easier for future upgrades.

I declare them then assign a value to them but the compiler insists they are not referenced thus wasting space. Why?

As for MUI_TEXT below I'm not even declaring it in my script so how is it being detected??

******************
5 warnings:
Variable "STARTMENU_LINK_APP_FILENAME" not referenced, wasting memory!
Variable "STARTMENU_LINK_APP_NAME" not referenced, wasting memory!
Variable "STARTMENU_LINK_APP_UNINSTALL" not referenced, wasting memory!
Variable "STARTMENU_LINK_APP_HELP" not referenced, wasting memory!
Variable "MUI_TEXT" not referenced, wasting memory!


********************

Var ALREADY_INSTALLED
Var STARTMENU_FOLDER
Var MUI_TEMP
var STARTMENU_LINK_APP_FILENAME
var STARTMENU_LINK_APP_NAME
var STARTMENU_LINK_APP_UNINSTALL
var STARTMENU_LINK_APP_HELP

!define STARTMENU_LINK_APP_NAME "Start XXXX"
!define STARTMENU_LINK_APP_FILENAME "XXX"
!define STARTMENU_LINK_APP_UNINSTALL "Uninstall"
!define STARTMENU_LINK_APP_HELP "View Help"


You are confusing compile-time commands with run-time.
!defines are for compile-time. Variables are for run-time.

You must set the value of the variables in the .onInit function of your installer using StrCpy.

e.g.

Function .onInit
StrCpy $STARTMENU_LINK_APP_NAME "Start XXXX"
StrCpy $STARTMENU_LINK_APP_FILENAME "XXX"
StrCpy $STARTMENU_LINK_APP_UNINSTALL "Uninstall"
StrCpy $STARTMENU_LINK_APP_HELP "View Help"
FunctionEnd

-Stu

Originally posted by Afrow UK
You are confusing compile-time commands with run-time.
!defines are for compile-time. Variables are for run-time.

You must set the value of the variables in the .onInit function of your installer using StrCpy.

e.g.
Function .onInit
StrCpy $STARTMENU_LINK_APP_NAME "Start XXXX"
StrCpy $STARTMENU_LINK_APP_FILENAME "XXX"
StrCpy $STARTMENU_LINK_APP_UNINSTALL "Uninstall"
StrCpy $STARTMENU_LINK_APP_HELP "View Help"
FunctionEnd

-Stu
I've changed it and am now getting different errors:

8 warnings:
unknown variable/constant "{STARTMENU_LINK_APP_NAME}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:160)
unknown variable/constant "{STARTMENU_LINK_APP_FILENAME}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:160)
unknown variable/constant "{STARTMENU_LINK_APP_UNINSTALL}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:161)
unknown variable/constant "{STARTMENU_LINK_APP_HELP}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:162)
unknown variable/constant "{STARTMENU_LINK_APP_NAME}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:232)
unknown variable/constant "{STARTMENU_LINK_APP_UNINSTALL}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:233)
unknown variable/constant "{STARTMENU_LINK_APP_HELP}" detected, ignoring (C:\XXX\YYY\Install\Install_NSIS\Setup.nsi:234)
Variable "MUI_TEXT" not referenced, wasting memory!

The variables are declared so why is it doing this?

Var ALREADY_INSTALLED
Var STARTMENU_FOLDER
Var MUI_TEMP
var STARTMENU_LINK_APP_FILENAME
var STARTMENU_LINK_APP_NAME
var STARTMENU_LINK_APP_UNINSTALL
var STARTMENU_LINK_APP_HELP

Let me guess, you've been referring to the variables with {} around them. Variables don't have {} around them, but defines do.

$VAR is a variable ${VAR} is a define

Var VAR makes a run-time variable called $VAR
!define VAR "value" makes a compile-time define called ${VAR}

If you are looking at using compile-time defines though, scrap all the Var commands and just use !define.

-Stu


Originally posted by Afrow UK
Let me guess, you've been referring to the variables with {} around them. Variables don't have {} around them, but defines do.

$VAR is a variable ${VAR} is a define

Var VAR makes a run-time variable called $VAR
!define VAR "value" makes a compile-time define called ${VAR}

If you are looking at using compile-time defines though, scrap all the Var commands and just use !define.

-Stu
Before I go messing with the code to which I now should get to compile without warnings can you state is it better to use run-time or compile-time variables/defines?

Hmmm would you perhaps know what MUI_TEXT is?

I am not declaring it anywhere, even did a Find in notepad and it can't find it but when I compile it keeps saying this:

1 warning:
Variable "MUI_TEXT" not referenced, wasting memory!


Please attach your script.

-Stu


Originally posted by Afrow UK
Please attach your script.

-Stu
Here goes.....quite long so far.

;**************************************************************************************************
;**************************************************************************************************
;Setup program, VERSION 1.00
;**************************************************************************************************
;**************************************************************************************************

;--------------------------------
;Include Modern UI

!include "MUI.nsh"
!include "Library.nsh"

;--------------------------------
;GENERAL

Var ALREADY_INSTALLED
Var STARTMENU_FOLDER
Var MUI_TEMP
var STARTMENU_LINK_APP_FILENAME
var STARTMENU_LINK_APP_NAME
var STARTMENU_LINK_APP_UNINSTALL
var STARTMENU_LINK_APP_HELP

;**************************************************************************************************
;Name and file
;**************************************************************************************************
Name "XXX 2005"
SetFont "MS Sans Serif" 8
OutFile "Setup.exe"

;**************************************************************************************************
;Default installation folder
;**************************************************************************************************
InstallDir "$EXEDIR\XXX YYY\"

;**************************************************************************************************
;Get installation folder from registry if available
;**************************************************************************************************
InstallDirRegKey HKLM "Software\XXX\YYY\Uninstall" ""

BrandingText /TRIMLEFT XXX 2005 Setup"

XPStyle on



;--------------------------------
;INTERFACE CONFIGURATION

;**************************************************************************************************
;General
;**************************************************************************************************
!define MUI_ICON "Images\setup.ico"
!define MUI_UNICON "Images\setup.ico"
!define MUI_LICENSEPAGE_CHECKBOX
!define MUI_ABORTWARNING
XPStyle on

;**************************************************************************************************
;Install interface
;**************************************************************************************************
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_HEADERIMAGE_BITMAP "Images\header.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "Images\welcome.bmp"
!define MUI_FINISHPAGE_TITLE XXX 2005 has been installed."
!define MUI_FINISHPAGE_TEXT_REBOOTNOW "Reboot now (Recommended)"

!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\XXX\YYY"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"

;**************************************************************************************************
;Uninstall interface
;**************************************************************************************************
!define MUI_HEADERIMAGE_UNBITMAP "Images\header.bmp"
!define MUI_HEADERIMAGE_UNBITMAP_NOSTRETCH

;**************************************************************************************************
;Start Menu link names
;**************************************************************************************************
;!define STARTMENU_LINK_APP_NAME "Start XXX"
;!define STARTMENU_LINK_APP_FILENAME "XXX"
;!define STARTMENU_LINK_APP_UNINSTALL "Uninstall"
;!define STARTMENU_LINK_APP_HELP "View Help"


;--------------------------------
;PAGES

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "Data\license.txt"
;!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;--------------------------------
;LANGUAGES

!insertmacro MUI_LANGUAGE "English"




;--------------------------------
;INSTALLER SECTIONS ###############################################################################


;/////////////////////////////////////////////////////////
Section "Standard installation" StandardInstall
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

SetOutPath "$INSTDIR" ;Root folder of installation

;**************************************************************************************************
;PROGRAM FILES
;**************************************************************************************************

File WorkMate.exe

;**************************************************************************************************
;PROGRAM DOCUMENTATION FILES
;**************************************************************************************************

SetOutPath "$INSTDIR\Help" ;Root folder of installation + \Help
File /r "Help\*.*"

;**************************************************************************************************
;Store installation folder
;**************************************************************************************************
WriteRegStr HKLM "Software\XXX\YYY" "Install Folder" $INSTDIR

;**************************************************************************************************
;Create uninstaller
;**************************************************************************************************
WriteUninstaller "$INSTDIR\Uninstall.exe"

;**************************************************************************************************
;Write uninstall registry info for Windows Add/Remove Programs option in Control Panel
;**************************************************************************************************
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY\" "DisplayName" "YYY"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY\" "Publisher" "XXX"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY\" "URLInfoAbout" "http://www.xxx.net"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY\" "Publisher" "XXX"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY\" "DisplayVersion" "2004"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY\" "UninstallString" "$INSTDIR\Uninstall.exe"

;**************************************************************************************************
;Write Start Menu links
;**************************************************************************************************

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application

;Create Start Menu shortcuts
CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\$STARTMENU_LINK_APP_NAME.lnk" "$INSTDIR\$STARTMENU_LINK_APP_FILENAME.exe"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\$STARTMENU_LINK_APP_UNINSTALL.lnk" "$INSTDIR\Uninstall.exe"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\$STARTMENU_LINK_APP_HELP.lnk" "$INSTDIR\Help\index.htm"

!insertmacro MUI_STARTMENU_WRITE_END

SectionEnd

;/////////////////////////////////////////////////////////
Section "-Install VB6 runtimes"
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;Check if this is a new installation
IfFileExists "$INSTDIR\MyApp.exe" 0 New_Installation
StrCpy $ALREADY_INSTALLED 1

New_Installation:
!insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_NOTPROTECTED "VB6Runtime\msvbvm60.dll" "$SYSDIR\msvbvm60.dll" "$SYSDIR"
!insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED "VB6Runtime\oleaut32.dll" "$SYSDIR\oleaut32.dll" "$SYSDIR"
!insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED "VB6Runtime\olepro32.dll" "$SYSDIR\olepro32.dll" "$SYSDIR"
!insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_PROTECTED "VB6Runtime\comcat.dll" "$SYSDIR\comcat.dll" "$SYSDIR"
!insertmacro InstallLib DLL $ALREADY_INSTALLED REBOOT_PROTECTED "VB6Runtime\asycfilt.dll" "$SYSDIR\asycfilt.dll" "$SYSDIR"
!insertmacro InstallLib TLB $ALREADY_INSTALLED REBOOT_PROTECTED "VB6Runtime\stdole2.tlb" "$SYSDIR\stdole2.tlb" "$SYSDIR"

SetRebootFlag true

SectionEnd

;--------------------------------
;DESCRIPTIONS

;**************************************************************************************************
;Language strings
;**************************************************************************************************
LangString DESC_StandardInstall ${LANG_ENGLISH} "Standard installation."

;**************************************************************************************************
;Assign language strings to sections
;**************************************************************************************************
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${StandardInstall} $(DESC_StandardInstall)
!insertmacro MUI_FUNCTION_DESCRIPTION_END




;--------------------------------
;UNINSTALLER SECTIONS #############################################################################


;/////////////////////////////////////////////////////////
Section "Uninstall"
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;**************************************************************************************************
;Delete files created upon installation
;**************************************************************************************************

Delete "$INSTDIR\Help\*.*"
Delete "$INSTDIR\*.*"

;**************************************************************************************************
;Delete folders created upon installation
;**************************************************************************************************
RMDir /r "$INSTDIR"

;**************************************************************************************************
;Delete Start Menu links
;**************************************************************************************************

!insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP

Delete "$SMPROGRAMS\$MUI_TEMP\$STARTMENU_LINK_APP_NAME.lnk"
Delete "$SMPROGRAMS\$MUI_TEMP\$STARTMENU_LINK_APP_UNINSTALL.lnk"
Delete "$SMPROGRAMS\$MUI_TEMP\$STARTMENU_LINK_APP_HELP.lnk"

;Delete empty start menu parent diretories
StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"

RMDir $MUI_TEMP

ClearErrors

;**************************************************************************************************
;Delete created registry keys
;**************************************************************************************************
DeleteRegKey HKLM "Software\XXX"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YYY"

SectionEnd

;/////////////////////////////////////////////////////////
Section "-un.Uninstall VB6 runtimes"
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\msvbvm60.dll"
!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\oleaut32.dll"
!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\olepro32.dll"
!insertmacro UnInstallLib REGDLL SHARED NOREMOVE "$SYSDIR\comcat32.dll"
!insertmacro UnInstallLib DLL SHARED NOREMOVE "$SYSDIR\asycfilt.dll"
!insertmacro UnInstallLib TLB SHARED NOREMOVE "$SYSDIR\stdole2.tlb"

SectionEnd

;--------------------------------
;INIT SECTION

Function .onInit

StrCpy $STARTMENU_LINK_APP_NAME "Start XXXX"
StrCpy $STARTMENU_LINK_APP_FILENAME "XXX"
StrCpy $STARTMENU_LINK_APP_UNINSTALL "Uninstall"
StrCpy $STARTMENU_LINK_APP_HELP "View Help"

SetOutPath $TEMP
File /oname=spltmp.bmp "Images\splash.bmp"

; optional
; File /oname=spltmp.wav "Data\splash.wav"

splash::show 1000 $TEMP\spltmp

Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normal, and '-1' if some error occured.

Delete $TEMP\spltmp.bmp
; Delete $TEMP\spltmp.wav
FunctionEnd

Uhm, what's Var MUI_TEMP doing there then (under GENERAL)... :p

You should also change most of your custom Var's to defines as they will be wasting memory on run-time. Variables are created for exactly that - for thier data or content to be varied (changed). If you aren't changing their data at all then there is no need to use them!

You should do this:
!define STARTMENU_LINK_APP_FILENAME "Start XXXX"
!define STARTMENU_LINK_APP_NAME "XXX"
!define STARTMENU_LINK_APP_UNINSTALL "Uninstall"
!define STARTMENU_LINK_APP_HELP "View Help"

Then use e.g. ${STARTMENU_LINK_APP_FILENAME} for where you want it to be placed. You can then scrap the StrCpy stuff in your .onInit function.

Edit: When I said attach your script I meant attach the actual .nsi file using the file upload :p

-Stu


Originally posted by Afrow UK
Uhm, what's Var MUI_TEMP doing there then (under GENERAL)... :p

You should also change most of your custom Var's to defines as they will be wasting memory on run-time. Variables are created for exactly that - for thier data or content to be varied (changed). If you aren't changing their data at all then there is no need to use them!

You should do this:
!define STARTMENU_LINK_APP_FILENAME "Start XXXX"
!define STARTMENU_LINK_APP_NAME "XXX"
!define STARTMENU_LINK_APP_UNINSTALL "Uninstall"
!define STARTMENU_LINK_APP_HELP "View Help"

Then use e.g. ${STARTMENU_LINK_APP_FILENAME} for where you want it to be placed. You can then scrap the StrCpy stuff in your .onInit function.

Edit: When I said attach your script I meant attach the actual .nsi file using the file upload :p

-Stu
Okay I'm going to make them non-variables.

As for MUI_TEMP that's needed under the section:
;Delete Start Menu links

It stores the folder name, agreed?

Also the compiler keeps going on about MUI_TEXT as being not referenced but it's not even declared anywhere?

Thanks so far, you're being a big help.

You don't have to declare any of these MUI variables.

This warning is caused by a bug in your Modern UI code somewhere, please review that part.


Originally posted by Joost Verburg
You don't have to declare any of these MUI variables.

This warning is caused by a bug in your Modern UI code somewhere, please review that part.
Which type of MUI variables are you refrencing? I do believe there are any that aren't used.

MUI_TEMP is a variable used by Modern UI (hence MUI!) You should change the name to something else.

-Stu