Re: Linking options for debugging
- From: "Jason Polychronopulos" <jpoly@xxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 13:56:13 +0100
Hi Oleg,
Many thanks for your reply, It looks very interesting. It may take some time
for me to digest!
I will get back with some extra information if it remains a problem.
Once again thanks.
Best Regards,
Jason
"Oleg Starodumov" <com-dot-debuginfo-at-oleg> wrote in message
news:eDF%23CQxUGHA.5852@xxxxxxxxxxxxxxxxxxxxxxx
I have some questions to do with debug linking in VC7.1:
1) Is it correct that all libs that you link in ( both statis and
dynamic )
must be linked with the same version of the C runtime library ( = same
/MD
flag ).
Static libraries: You should link the application with a version of CRT
library
that implements all CRT functions and variables used by the static library
(that is, if e.g. the static library uses functions from debug CRT
library,
you have to link the application with debug version of CRT to satisfy the
linker)
DLLs: no (DLLs can be linked with other versions of CRT, unless the
interface
of those DLLs requires sharing the same CRT with your application (which
in turn
happens if e.g. heap memory gets allocated in the application and released
in
the DLL, or vice versa))
2) If no ( = it is allowed to mix different versions ) then are there
special flags etc. you need to set to make it work?
Sometimes you might need /nodefaultlib linker option to enforce
the version of CRT that you want to use.
3) To debug your source code you only need to set the /Zi flag ( make the
debug database ). ( i.e. you can link with /MD and still debug )?
Yes (assuming that you also use /debug linker option).
Debug version of CRT is not needed to debug your own code.
4) I have the following link error, I get this error when we link with
/MD -> when we link with /MDd everything just compiles and links fine.
Most likely, these errors come from the fact that the application uses
some functions
from debug version of CRT library (debug versions of memory allocation
functions).
It usually happens when your source files are set up to perform memory
leak
checking with the help of debug CRT library, using something like this:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
If you want to link your application with release version of CRT,
you should remove those defines so that release versions of memory
allocation functions are used.
But if the .obj files mentioned in linker messages come from a static
library,
you have no choice other than to link the application with debug version
of CRT
(or use another version of the static library, which does not depend on
debug
CRT functions, if such version is available).
5) When I link with /MDd we can compile-link and execute with "start
without
debugging". But just with start, I get an exception thrown. Our program
is
linked with /MDd but I know that one third-party dll is linked with /MD
What is the call stack at the moment of the exception?
Regards,
Oleg
[VC++ MVP http://www.debuginfo.com/]
.
- References:
- Linking options for debugging
- From: Jason Polychronopulos
- Re: Linking options for debugging
- From: Oleg Starodumov
- Linking options for debugging
- Prev by Date: Re: Linking options for debugging
- Next by Date: Re: MiniDumpNormal returns false
- Previous by thread: Re: Linking options for debugging
- Next by thread: Re: MiniDumpNormal returns false
- Index(es):
Relevant Pages
|
Loading