Optimization misexecutes static library calls


I have created a static library and I want to integrate it into my project.
The static library can only be debugged? that is, you can only create lib.a with debug?

Later I integrate lib.a to my project but when I execute the release with optimization -O2, the calls to the functions of my library are not executed as they should.

With the optimization level at -O0 it works fine.
Any solution? What is the best optimization?

Best regards.