  We provide an upper bound for the number of limit cycles that planar
polynomial differential systems of a given degree may have. The bound turns out
to be a polynomial of degree four in the degree of the system. The strategy
brings together variational and dynamical system techniques by transforming the
task of counting limit cycles into counting critical points for a certain
smooth, non-negative functional, through Morse inequalities, for which limit
cycles are global minimizers. We thus solve the second part of Hilbert's 16th
problem providing a uniform upper bound for the number of limit cycles which
only depends on the degree of the polynomial differential system.
