# Class memoir Error: listing is not a counter

I am trying to use \counterwithout{listing}{chapter}

But memoir keeps complaining Class memoir Error: listing is not a counter

\documentclass[english,12pt,a4paper,twoside]{memoir}
\usepackage{listings}
\AtBeginDocument{\counterwithout{listing}{chapter}}

\begin{document}  % test5.tex:5: Class memoir Error: listing is not a counter.
\chapter{Hi}

\begin{lstlisting}[caption=Code,label=acode]
Code
\end{lstlisting}

Something...

\end{document}


Memoir code:

\newcommand{\@ifbothcntrs}[3]{%
\@ifundefined{c@#1}{% counter undefined
\@memerror{#1 is not a counter}{\@eha}}%
{% else counter is defined
\@ifundefined{c@#2}{% within undefined
\@memerror{#2 is not a counter}{\@eha}}%
{% else both counter and within  are defined
#3}}}

\newcommand{\counterwithin}{\@ifstar{\@csinstar}{\@csin}}
\newcommand{\@csinstar}[2]{%

• Thanks! I see now that I should include the package minted (which defines the counter listing) instead of including the package listings (which defines the counter lstlisting. – user Aug 2 '20 at 18:47