FAQ #26: Compilation of DCMTK-based program fails w/ LNK2005

Frequently Asked Questions regarding DCMTK

Moderator: FAQ Team

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

FAQ #26: Compilation of DCMTK-based program fails w/ LNK2005

#1 Post by Marco Eichelberg » Tue, 2004-11-09, 09:31

:?: I am developing an application on Microsoft Visual C++ (MSVC) that uses DCMTK. When I try to compile and link my application against the DCMTK libraries, the linker fails with error LNK2005 and reports warning LNK4098, e.g.

Code: Select all

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in MSVCRTD.lib(MSVCRTD.dll) 
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library 
:!: The problem is that the linker tries to combine different, incompatible versions of the Visual C++ runtime library into a single binary. This happens when not all parts of your project and the libraries you link against are generated with the same code generation options in Visual C++. Do not use the /NODEFAULTLIB workaround, because strange software crashes may follow. Fix the problem!

DCMTK is by default compiled with the "Multithreaded" or "Multithreaded Debug" code generation option (the latter for Debug mode). Either change the project settings of all of your code to use these code generation options, or change the code generation for all DCMTK modules and re-compile. MFC users beware: DCMTK should be compiled with "Multithreaded DLL" or "Multithreaded DLL Debug" settings if you want to link the libraries into an MFC application.

Note: You can change the code generation options centrally in file dcmtk/CMakeLists.txt by replacing "/MT" with "/MD" and "/MTd" with "/MDd". You then have to run CMake to create new project files for the complete DCMTK toolkit. If you do this change, however, please note that you also have to provide all external libraries (zlib, openssl etc.) in pre-compiled versions generated with "/MD" or "/MDd". Alternatively, you can disable the use of this external libraries in CMake.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest