Just a few question to try to better understand your problem.
How did you create the project (CubeMX or System Workbench)?
How did you create the Release (no-debug) build configuration (if you have to, that is if you created the project using CubeMX)?
How did you select the Release build? Did you activate the Release build configuration (project >> Build Configurations >> Set Active >> Release or Debug)?
Build configurations place their output in directory trees named after the configuration (Debug or Release); Could you check the debugging configuration (project >> Debug As >> Debug Configurations...) and verify it selects the right executable (Debug/program.elf or Release/program.elf)?
Could you compare the .project/.cproject files before and after doing the Release build?
I do not think the difference you note above was the real cause of the error, as neither the compiler nor the link editor should use these settings, but to investigate further we really need more information.
Thanks for your patience and help,