Re: Linking options for debugging



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/]





.



Relevant Pages

  • Re: WM_TIMER crash (maybe)?
    ... addition, I suspect that, given the debug dialog IS, in fact, a dialog, and therefore it ... For example, if you install VC, it typically installs the ... that you could be replacing older DLLs with the latest redistributable DLLs. ... the rest were system DLLs, including OLE/COM libraries ...
    (microsoft.public.vc.mfc)
  • Re: Debug library crashes when linked with Release build
    ... application) but no optimizations and creating debug database to ... I was using the debug CRT, optimizations disabled, and debug ... but does anyone know for sure what is causing this? ... actual 2 libraries with the debug CRT that I was linking (one ...
    (microsoft.public.dotnet.languages.vc)
  • Re: How to dllimport a dllexported class
    ... You do need to link to the CRT, and all files in this library should ... Using DLLs is no different that using static libraries in that ... you need to treat it like static linking WRT having identical ... flawlessly for probably thousands of programs that use the CRT DLLs, ...
    (microsoft.public.dotnet.languages.vc)
  • Using MFC/CRT DLLs as "private assemblies"
    ... I want to put MFC and CRT in the program directory and have it call those ... debug version alone.) ... If the MFC and CRT dlls and manifests are placed in the "release" directory, ... The manifest file "filename.manifest" ...
    (microsoft.public.vc.mfc)
  • Re: Static Library Option?
    ... installed all the DLLs, including debug, but 2005 does not. ... libraries also and don't want to participate in DLL hell. ... You don't have to go through the MFC option. ...
    (microsoft.public.vstudio.development)

Loading