Static or dynamic linking to CRT

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Posts: 3
Joined: Mon, 2007-10-29, 22:41

Static or dynamic linking to CRT

#1 Post by BudricB » Tue, 2009-11-03, 21:45

when using CMake in windows XP the MSVC solution is set to statically link to the CRT. My application is also set to /MT. I was wondering if there are any memory problems (or other problems) that could result in this.

For example if you consider
DcmItem::findAndGetElement (const DcmTagKey &tagKey, DcmElement *&element, const OFBool searchIntoSub=OFFalse);

You pass a reference to a pointer of DcmElement which gets created by the function findAndGetElement. I am assuming that I have to free that object when I'm done, correct? So basically you're allocating memory in a library with 1 version of statically linked CRT and freeing it potentially using another version of the CRT. Anyone run into any problems with this? Am I wrong with some of my assumptions?

Thanks for clarifying this for me.

*EDIT* After reading some of the code I see I don't have to free that object returned. But I'd still like a confirmation if there are any problems with statically linking to CRT.

Marco Eichelberg
Posts: 1280
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany

#2 Post by Marco Eichelberg » Sat, 2009-12-05, 16:58

As far as I know, you can never mix Windows code generated with different CRT settings (e.g. /MT and /MD) - the linker will report an error, and rightly so. The only case where this situation might occur is if you have DCMTK code both in your main application and in a DLL. No idea whether the heap management code is compatible - MSDN should know.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest