I think the good way to do that is to introduce the Expenditure function which awesomely solves your problem.
The Expenditure function gives the money one has to spend to achieve a given level of utility, given a utility function $u$ and the vector of prices $p$.
$e(p,u^*)=min_{x \in \mathbb{R}_+^n,u(x) \geq u^*}p \cdot x$
Then you can express your compensating variation in two equivalent ways:
$CV=e(p_1,u_1)-e(p_1,u_0)=e(p_0,u_0)-e(p_1,u_0)$ where $p_0$ and $p_1$ are the old and new prices and $u_0$ and $u_1$ are the old and new utility. One can note that it can be translated as: if given $CV$ in compensation for the change, then the consumer would be indifferent to that change.