[Tex/LaTex] How to understand the LaTeX warning “there were undefined references”

cross-referencingwarnings

I am running this LaTeX file through pdflatex and getting these warnings:

latex warning: there were undefined references.
latex warning: label(s) may have changed. Rerun to get cross-reference right.

and also some more warnings like this:

latex warning: reference 'lastpage' on page 76 undefined on input line 3200.

on every page end.

My LaTeX file is like this

\documentclass[a4paper,leqno,twoside]{article}

\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{multirow}

\renewcommand{\familydefault}{\sfdefault}

\usepackage{color}
\usepackage[colorlinks=true]{hyperref}
\usepackage{draftwatermark}
\SetWatermarkText{EXPERIMENTAL}
 \SetWatermarkScale{0.6}
 \usepackage{parskip}

 \graphicspath{{Figure/}}

  \let\oldsection\section
 \renewcommand{\section}{\clearpage\oldsection} 
 \begin{document}



  % Issued by {Name, acronym, department, phone}
 \issuedby{vrebwr}
 % Checked by
  \checkedby{-}
  % Approved by
 \approvedby{-}
  % Document title. Use \doctitleShort{} to insert a shorter title in the header.
  \doctitle{test numbers with id}
  \doctitleShort{document for tests}
  % Publish date
 \publishdate{\today}


  % Titlepage
 \frontmatter % Should be on first page
 \maketitle



 \vspace*{08eX}
  \begin{center}
   \subsection*{Abstract}
   \end{center}

  \noindent
     it contains information about tests.
   \newpage
    \mainmatter
    % Main pages. This command should be on page 2 or later.
    \phantom{phantom}
   \cleardoublepage

   \subsection*{Change Record}

  \begin{itemize}
  \item R.1: Initial version.
   \begin{itemize}
  \item  generation of documentation using the vrebwr
    \end{itemize}
   \end{itemize}

    \cleardoublepage

  \setcounter{tocdepth}{2}
    \tableofcontents 

   \cleardoublepage

   \section{ How to read the tset information}

   \begin{enumerate}
     \item information how to read
    \item information of tests
    \end{enumerate}

    \section{test numbers}

   \subsection*{1, temperature sensor. }
   \addcontentsline{toc}{subsection}{ 1, temperature sensor.}
   \subsubsection*{data}
   some data regarding test where we performed
   \subsubsection*{values}
   temperature sensor value here three or more.
    \subsubsection*{reason}   
    why we get like this.
     \newpage

    \subsection*{2, humidity sensor. }
    \addcontentsline{toc}{subsection}{ 2, humidity sensor.}
   \subsubsection*{data}
   some data regarding test where we performed
   \subsubsection*{values}
   humidity sensor value here three or more.
    \subsubsection*{reason}   
     why we get like this.

  \subsection*{3, pressure sensor. }
   \addcontentsline{toc}{subsection}{ 3, pressure sensor.}
   \subsubsection*{data}
   some data regarding test where we performed
   \subsubsection*{values}
   pressure sensor value here three or more.
   \subsubsection*{reason}   
  why we get like this.
   \newpage
  \end{document}

In the above LaTeX file I have around 100 tests. I used the * symbol to eliminate numbering in subsections, because I am using test names with number so there is no need to add numbering. It looks bad in the PDF, so I tried to add that test name and number in table of contents by using this command:

\addcontentsline{toc}{subsection}{1,temperature sensor.}

When I used this command I am getting errors like as I explained above. I searched and I found some reasons why this error occurred, because of \label{} and \ref{} is not used like that. But I don't know how to use that in my file. Can anyone help me with it?

Best Answer

Getting a warning about undefined references after the first LaTeX run is nothing to worry about. Just rerun LaTeX once or twice more and all cross-references should be resolved (including the one to lastpage).

On the other hand, if you have typos in your labels and/or in your cross-referencing commands, the warnings won't go away upon recompiling the code once or twice more. At that state, they become useful because they tell you something is amiss and needs to be corrected.

Related Question