A buffer overrun occurs but only in debug version

I cannot debug my software because in debug version I have a message: :" A buffer overrun has occurred in [name].exe which has corrupted the program's internal state. Press break to debug the program or Continue to terminate the program.
For more details please see Help topic 'How to Debug Buffer Overrun Issues'.

After pressing 'Break' the debugger stops at    _CRT_DEBUGGER_HOOK(_CRT_DEBUGGER_GSFAILURE);
in gs_report.c which tells me nothing.

I've noticed the strange thing in the output window just before this failure:
'recorder.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_5490cd9f\msvcp80d.dll', Symbols loaded.
'recorder.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\msvcr80.dll', No symbols loaded.
Two versions of the CRT were loaded for my program. That was not normal.
I solved the problem already but I decided to post it. The cause was simple but quite hard to track. I will answer for it myself. Maybe somebody will use this solution in the future.
LVL 2
mjoachiamiakAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mjoachiamiakAuthor Commented:
The problem was that some of the libraries I used was compiled with /GL (global optimization) linker option which according to the http://msdn.microsoft.com/en-us/library/0zza0de8.aspx 
cannot be used together with /Z7, /Zi, /ZI  options.
In other words in debug version of my application I was trying to use release version of the library and it gave this strange buffer overrun error.

BR.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.