# Why does \pageref{LastPage} give me “??” rather than page number of the last page?

I am trying to use the lastpage package in order to have footers with the page number given in the form "Page x of y", where y is the page number of the last page.

This should be straightforward, but I'm getting instead: "Page x of ??"; i.e., I'm getting a pair of question marks rather than a page number.

I've distilled the problem down in order to minimize dependencies, etc. to:

\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\cfoot{\thepage\ of \pageref{LastPage}}
\begin{document}
text
\newpage
text
\newpage
text
\end{document}

Does anyone have any idea about what I could be missing to cause \pageref{LastPage} to give me "??"?

• Did you run it twice? – Peter Grill Sep 16 '11 at 22:14
• Your code compiles OK in my system. Have you compiled it twice? – Gonzalo Medina Sep 16 '11 at 22:14
• Found something interesting, if you use pdflatex (Windoze) and specify -aux-directory=DIR, the second (or third, fourth, fifth or sixth for that matter) passes will not update the references correctly (arrrrgggghv) – davidc Mar 27 '18 at 1:20