A variational principle in physics, such as the principle of least action or Fermat's principle in optics, allows one to describe the system in a global manner and to solve it using the calculus of variations. In thermodynamics, such a principle would allow a Lagrangian formulation. The Gouy-Stodola theorem can be used as the basis for such a variational principle, in thermodynamics. It has been proven to satisfy the necessary conditions.