Version 1.4 of listings.sty includes the following code snippet:
\AtBeginDocument{
\@ifundefined{thechapter}{\let\lst@ifnumberbychapter\iffalse}{}
\lst@ifnumberbychapter
\newcounter{lstlisting}[chapter]
\gdef\thelstlisting%
{\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@lstlisting}
\else
\newcounter{lstlisting}
\gdef\thelstlisting{\@arabic\c@lstlisting}
\fi}
Version 1.3 of nostarch.cls contains the following code snippet:
\renewcommand \thelstlisting
{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}
In other words, nostarch tries to redefine a counter (lstlisting) in the preamble which will only be defined by listings at the begin of the document body. This results in the error message you observed.
Solution: Copy nostarch.cls to your working directory and rename the copy to, say, mynostarch.cls. In the renamed copy, replace the above code lines with
\AtBeginDocument{%
\renewcommand \thelstlisting
{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}%
}
Then, replacing nostarch with mynostarch in your example (and actually typesetting something in the document body) should compile without errors.
EDIT: As Peter Grill pointed out in a (now deleted) comment, adding \def\thelstlisting{} before \documentclass will remove the error message in your original example. However, nostarchs attempted redefinition of \thelstlisting (replacing the dot with a dash) won't be applied. Here's an alternative solution that doesn't involve modifying a custom copy of nostarch.sty:
\def\thelstlisting{}
\documentclass[nocfonts]{nostarch}
\makeatletter
\AtBeginDocument{%
\renewcommand \thelstlisting
{\ifnum \c@chapter>\z@ \thechapter-\fi \@arabic\c@lstlisting}%
}
\makeatother
\begin{document}
\chapter{First}
\begin{lstlisting}[caption={A listing}]
foo
\end{lstlisting}
\end{document}