Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why can't you use the debug/release version of a lib interchangeably

Tags:

libstdc++

In C++, most of the libs come in Debug/Release versions. Question 1. What are the big difference between Debug and Release versions (e.g. what advantages do you have using one versus the other).

Question 2. A lib is just has an implementation of the functions, how does a function implementation change if you are using debug/release versions?

Question 3. Can you ever build your app in debug mode and use a release version of a lib?

Thanks.

like image 332
user205834 Avatar asked Oct 14 '22 19:10

user205834


2 Answers

Answer 1

Debug Mode

  • Contains Symbols for debugging. In other words your debugger can link the current location of the program its location in the source code
  • Potentially contain debug only code eg code that is in a #ifdef DEBUG block

Release Mode

  • Faster because it has remove debug related code.
  • Limited in debugging because it lacks symbols.

Answer 2

  • Depends on how the Library Is implemented

Answer 3

  • Only if they have the same ABI.
like image 59
mikek3332002 Avatar answered Dec 20 '22 13:12

mikek3332002


Debug versions are usually built with very few optimizations on -- therefore when you step through them in a debugger with source, there is a good chance that there is a good mapping between source line and what's going on in the program. When you step through highly optimized code, it doesn't map back to source very well, and is harder to debug.

Also, whenever someone uses an #ifdef DEBUG or equivalent, that code isn't there in the release version (of course). This could be extra error checking, logging, asserts, etc.

Normally, the interface of the function shouldn't be different between debug and release, so you can normally link debug and release together without much trouble.

However, there are some cases (especially on Windows) that it becomes very difficult because of DLL loading built into some libs. Some may try to load debug versions of DLL's and some might want release. These can't both be loaded into the same process.

like image 25
Lou Franco Avatar answered Dec 20 '22 12:12

Lou Franco