For the given expression, I can make the following steps:
$$\int^\infty_{-\infty} \cos^2x \,dx = \frac{1}{2}\int^\infty_{-\infty} \cos 2x\, + 1\, dx\\ \hspace{19mm}= \frac{1}{2} \left\{ \frac{1}{2}\sin2x + x \right\}\bigg\rvert^\infty_{-\infty}\\ \hspace{13mm}= \frac{1}{4} \sin2x \, \bigg\rvert^\infty_{-\infty} + x\,\bigg\rvert_{\infty}$$
I understand that $\lim_{x \rightarrow 0} \sin x$ is not defined. Thus the last line indicates that the integral is not defined.
Given that $1 \geq \cos^2 x \geq 0\, \forall \, x \in \mathbb{R}$. Should not the integral be $\infty$ instead of not defined?
$\int _{2k\pi } ^{2(k+1)\pi } \cos ^{2} (x) \, dx =\pi$. Add these integrals over $k$.