Marco Eichelberg OFFIS DICOM Team

Joined: 02 Nov 2004 Posts: 1156 Location: Oldenburg, Germany
|
Posted: Tue, 2004-11-09, 10:31 Post subject: FAQ #26: Compilation of DCMTK-based program fails w/ LNK2005 |
|
|
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: | 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. |
|