C++ Static Library Problems [RESOLVED]

Started by
5 comments, last by F1N1TY 16 years, 5 months ago
Hey guys. I'm having issues with a static library (.lib). The best way to describe it, is to show an example. If I build the library in RELEASE mode, then reference this library in another project then build that project in RELEASE mode, everything works fine. If I build that project in DEBUG mode, however, (still using the RELEASE built lib) then the program crashes. The same thing goes if I build the library in DEBUG mode. Works fine to build the project in DEBUG mode, but crashes when built under RELEASE. What could POSSIBLY be causing this? (I've created new solutions/projects, and everything, already). Visual Studio 2005 Standard SP1 Windows XP Pro. Thanks for the help! [Edited by - F1N1TY on November 7, 2007 1:24:16 PM]
"I'd rather know one thing, no matter how ordinary, than discourse endlessly on great issues." -- Galileo
Advertisement
When debugging you're meant to use debug version of both libraries. This is probably because the 2 codebases are being built with different versions of the crt (c runtime) which would inevitably lead to heap corruption.

The debug libraries contain extra debugging information and safety checks at the cost of speed.
How do I ensure both builds use the same CRT version?
"I'd rather know one thing, no matter how ordinary, than discourse endlessly on great issues." -- Galileo
Quote:Original post by F1N1TY
How do I ensure both builds use the same CRT version?

Usually, we generate debug and release builds of the DLL simultaneously and use a preprocessor conditional (#ifdef _DEBUG) in the client code to link to the appropriate library.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Why is it that common libraries like Opengl32.lib or Glu32.lib don't require the Debug/Release check in order to work?
"I'd rather know one thing, no matter how ordinary, than discourse endlessly on great issues." -- Galileo
Quote:Original post by F1N1TY
Why is it that common libraries like Opengl32.lib or Glu32.lib don't require the Debug/Release check in order to work?

Such libraries are very carefully written to make sure that no version-specific types or interfaces are passed across module-boundaries. This is one of the reasons you don't see any standard-library objects being used and why there seem to be so many redundant types (GLFloat and so on).

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Ahhh. I see now, thanks a bunch for the help guys!
"I'd rather know one thing, no matter how ordinary, than discourse endlessly on great issues." -- Galileo

This topic is closed to new replies.

Advertisement