I have a problem getting glossaries and acronyms to work. It works a few times, and then I compile again and I get tons of error messages

I have the \usepackage line and the \makeglossaries line in the preamble. So where should the \newacronym and \newglossaryentry lines go? In the document itself? In the preamble? Before or after \makeglossaries?
The \printglossaries line is at the end of the document, just before the \tableofcontents line, in case that makes any difference.