I have a question related to C++ dynamic libraries. Usually the C++ dynamic library is composed of a .lib file and a .dll file. If I understand well, the .lib file records the exported functions’ positions while the .dll contains the implementation. I know that the release version has some optimization, and hence the release dll and the debug dll should be different. Then what’s the main difference between release lib file and debug lib file? Is there a way to tell a lib (or dll) file is a release version or a debug version? What would happen if a release version program invokes a debug version library? Thanks!
I have a question related to C++ dynamic libraries. Usually the C++ dynamic library
Share
Please be aware that “Release” and “Debug” are just labels for a whole set of compiler and linker flags and settings, and often an internal “Release” build will still generate debugging information but will have higher optimization settings.
Therefore there is no standard way to tell if a lib or DLL is a “release” or a “debug” version unless it is explicitly indicated by something like a “d” postfix or the location of the library.
What happens when a “release” configuration executable calls into a “debug” configuration library depends on the specific compilation and linker settings that are different between the two. In nearly all cases you will have lots of trouble, sometimes very overtly, sometimes a little more insidiously. Some common sources of trouble:
Both libraries are likely to be using different versions of the run-time libraries, and may have different copies of certain variables that are supposed to be static and the same across all libraries in an executable, such as the memory allocation pool and its counters / sentinels. A symptom would be that you get strange memory allocation / deallocation bugs.
The libraries might be assuming different conventions in the standard library, for example security settings or iterator debugging. This will make the memory layouts of “standard” containers actually different across the libraries, and you’ll get access violations if you’re lucky or unpredictable behavior if you’re not.