  We show a connection between global unconstrained optimization of a
continuous function $f$ and weak KAM theory for an eikonal-type equation
arising also in ergodic control. A solution $v$ of the critical Hamilton-Jacobi
equation is built by a small discount approximation as well as the long time
limit of an associated evolutive equation. Then $v$ is represented as the value
function of a control problem with target, whose optimal trajectories are
driven by a differential inclusion describing the gradient descent of $v$. Such
trajectories are proved to converge to the set of minima of $f$, using tools in
control theory and occupational measures. We prove also that in some cases the
set of minima is reached in finite time.
