[Tex/LaTex] Reference source code line in minted package

cross-referencingminted

Does anybody know a working example, where a source code line is reference in minted?
I have not found any help till now how to do this?

\begin{minted}[linenos=true]{c++}
    bla bla bla bla ;   \label{myline}
\end{minted}

The above does not work, unfortunately, there is not commandchars or excape for latex commands only for math?

Thanks for any help!!

Best Answer

Use mathescape, then put your \label in math mode in a comment:

\begin{minted}[linenos=true, mathescape]{c++}
    i = i + 1 ;  
    j = j + 1 ; // The important line $\label{myline}$
    k = k + 1 ;
\end{minted}
The important line is line \ref{myline}.