The Gouy-Stodola Theorem is the theoretical basis for allocating irreversibility and for identifying the maximum possible efficiency for any kind of energy conversion system. The well-known theorem is re-obtained in this paper, relaxing the hypothesis about a constant value for temperature and pressure of the reference environment. The equations that have been driven taking into account the variation of reference temperature and pressure show that two additional terms appear in both reversible and irreversible maximum output work, besides the well-known terms. These additional terms take into account the available work (exergy) destruction related to the variation of the ambient condition during the considered time interval. In this way the Gouy-Stodola Theorem still holds, but the allocation of exergy destruction is generally different from that calculated in the usual hypothesis of constant temperature and pressure of the reference environment. The Gouy-Stodola Theorem is also used in various textbooks for defining the flow-exergy of a material stream crossing the boundaries of the control volume. The same approach is applied in this paper, highlighting the differences and the difficulties related to the variation of the reference pressure and temperature in the reference environment.