Not long ago I generated the Hex file for a code which had not any difference for each environment, compiling either from within Proteus, as well as on the same compiler, but now externally (by its own IDE), and I noticed a significant difference in size of generated files; The file generated on Proteus did not work at real device, only on simulation, but I did not go further to check the reason. I would recmmend you have a look at the makefile file as well as the build parameters in Proteus to check if there is any difference in terms of optimization or any other aspect.
If you have to make changes depending on each environment, you could think about adding #ifdef directives wherever there are changes on code in order to instruct compiler to make conditional assembling. By the way, are you generating this file on release or debug mode?