Linking with VS2005

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

Linking with VS2005

#1 Post by cgraus »

Hi all. I've read the FAQ and tried to work through some of the solutions suggested here, but nothing seems to be working for me. I've been given the job of moving a project which already links in to DCMTK from VC6 to VC2005. I'm also using the C++ standard library in the code for the first time, but I did this in VC6 and it compiles and links fine.

Having moved my project to VC2005 I am getting these linker errors:

"public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in dcmimage.lib(diyp2img.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >(int)" (??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z) already defined in dcmdata.lib(dcitem.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(int)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z) already defined in dcmimage.lib(diyp2img.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in dcmimage.lib(diyp2img.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in dcmimage.lib(diyp2img.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in dcmimage.lib(diyp2img.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in dcmimage.lib(diyp2img.obj)

That's just a sample of different clashes, but I get 48 errors in total. The project prior to my working on it did not contain standard headers at all, it used iostream.h, and mostly uses C libraries, actually. I've added iostream, string, vector, etc in my newer code, but it links against DCMTK in VC6, I've only started trying to build DCMTK because it does not link in VS2005.

I've tried to hard code some things to make absolutely sure that DCMTK does not use the pre standard headers, beyond that I've tried some of the things suggested in the FAQ and for other people below. I'd really appreciate any suggestions at this point in time. I should also mention that my attempts to force it to load standard headers was a waste of time, iostream.h, et al no longer exist in VC2005, trying to use them throws an error. So that can't be the problem, only one version of these files exists.

Christian

P.S. I should clarify that in updating this code, I removed all non standard headers from our project.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg »

To just ask the obvious, are you sure that all code you link against has been compiled with VS2005? Older object files remaining from a compilation with VC6 could cause problems of this kind.

cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

#3 Post by cgraus »

Yes, I'm sure, by virtue of the fact that I compiled it :-) I used CMake and got a VS2005 project that compiles perfectly, and I'm trying to link against it.

Thanks for your help.

Christian

cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

#4 Post by cgraus »

In addition, I created a new MFC VC2005 project, set it up to link to DCMTK, and added only the base base code to create a DicomImage from an CFileDialog returned path, and got these errors:

libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register@facet@locale@std@@CAXPAV123@@Z) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPAV12@@Z) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" (?_Locinfo_ctor@_Locinfo@std@@SAXPAV12@PBD@Z) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in msvcprt.lib(MSVCP80.dll)
libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprt.lib(MSVCP80.dll)
LIBCMT.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(lconv.obj) : error LNK2005: _localeconv already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(free.obj) : error LNK2005: _free already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(purevirt.obj) : error LNK2005: __purecall already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(strtoq.obj) : error LNK2005: __strtoi64 already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(strtoq.obj) : error LNK2005: __strtoui64 already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(abort.obj) : error LNK2005: _abort already defined in msvcrt.lib(MSVCR80.dll)
LIBCMT.lib(fflush.obj) : error LNK2005: _fflush already defined in msvcrt.lib(MSVCR80.dll)
LINK : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
MFCDICOMDlg.obj : error LNK2019: unresolved external symbol "void __stdcall _com_issue_error(long)" (?_com_issue_error@@YGXJ@Z) referenced in function "public: __thiscall _bstr_t::Data_t::Data_t(wchar_t const *)" (??0Data_t@_bstr_t@@QAE@PB_W@Z)
MFCDICOMDlg.obj : error LNK2019: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)" (?ConvertBSTRToString@_com_util@@YGPADPA_W@Z) referenced in function "public: char const * __thiscall _bstr_t::Data_t::GetString(void)const " (?GetString@Data_t@_bstr_t@@QBEPBDXZ)
LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _Netbios@4 referenced in function "unsigned char * __cdecl getMACAddress(unsigned char * const)" (?getMACAddress@@YAPAEQAE@Z)
dcmdata.lib(dcistrmz.obj) : error LNK2019: unresolved external symbol _inflateEnd referenced in function "public: virtual __thiscall DcmZLibInputFilter::~DcmZLibInputFilter(void)" (??1DcmZLibInputFilter@@UAE@XZ)
dcmdata.lib(dcistrmz.obj) : error LNK2019: unresolved external symbol _inflate referenced in function "private: unsigned long __thiscall DcmZLibInputFilter::decompress(void const *,unsigned long)" (?decompress@DcmZLibInputFilter@@AAEKPBXK@Z)
dcmdata.lib(dcistrmz.obj) : error LNK2019: unresolved external symbol _inflateInit2_ referenced in function "public: __thiscall DcmZLibInputFilter::DcmZLibInputFilter(void)" (??0DcmZLibInputFilter@@QAE@XZ)
dcmdata.lib(dcistrmz.obj) : error LNK2019: unresolved external symbol _inflateInit_ referenced in function "public: __thiscall DcmZLibInputFilter::DcmZLibInputFilter(void)" (??0DcmZLibInputFilter@@QAE@XZ)
dcmdata.lib(dcostrmz.obj) : error LNK2019: unresolved external symbol _deflateEnd referenced in function "public: virtual __thiscall DcmZLibOutputFilter::~DcmZLibOutputFilter(void)" (??1DcmZLibOutputFilter@@UAE@XZ)
dcmdata.lib(dcostrmz.obj) : error LNK2019: unresolved external symbol _deflate referenced in function "private: unsigned long __thiscall DcmZLibOutputFilter::compress(void const *,unsigned long,bool)" (?compress@DcmZLibOutputFilter@@AAEKPBXK_N@Z)
dcmdata.lib(dcostrmz.obj) : error LNK2019: unresolved external symbol _deflateInit2_ referenced in function "public: __thiscall DcmZLibOutputFilter::DcmZLibOutputFilter(void)" (??0DcmZLibOutputFilter@@QAE@XZ)

cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

#5 Post by cgraus »

In addition, all projects use the same build type as the library files themselves. I really appreciate any help here, I've been working on this for almost a week, and I am going in circles.

Genghis86
Posts: 10
Joined: Mon, 2005-08-29, 13:50
Location: Toronto, Canada
Contact:

#6 Post by Genghis86 »

These kinds of problems are usually caused when you are trying to link projects that have been built against a different CRT. Make sure all projects use the same CRT. For example, Debug versions could all link against "Debug Multithreaded DLL" version of the CRT, and Release versions would use "Multithreaded DLL".

But, if some projects use "Multithreaded DLL", and another uses simply "Multithreaded", such linking clashes will occur.

cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

#7 Post by cgraus »

Thanks, but as I said, I have been building with /MD exclusively. I am not mixing release and debug libraries. I am in the process of trying to get my project to build with /MT, but somewhere, _AFXEXT or _AFXDLL is being defined, which causes an error in afx.h.

cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

#8 Post by cgraus »

Thanks for the replies. I took the time to force all my other code to build with /MT, and rebuilt DCMTK to use /MT as well. It seems to be linking now ( still have an unrelated linking error to solve, so I can't say for sure )

Genghis86
Posts: 10
Joined: Mon, 2005-08-29, 13:50
Location: Toronto, Canada
Contact:

#9 Post by Genghis86 »

Have you considered using DLLs instead?

cgraus
Posts: 12
Joined: Wed, 2005-08-24, 22:56
Location: Australia

#10 Post by cgraus »

Are you suggesting I build DCMTK into DLLs and link to them ? How do I do that ?

FWIW, I am in the same boat I was a week ago - I have a VC6 project which builds with DCMTK, using /MD. I migrated to VC2005, and everything builds, but although I built DCMTK with VC2005, using /MD, when I try to link to my project, using /MD, I get these errors:

msvcprt.lib(MSVCP80.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in dcmimage.lib(diyp2img.obj)
msvcprt.lib(MSVCP80.dll) : error LNK2005: "public: void __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::`vbase destructor'(void)" (??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ) already defined in dcmdata.lib(dcitem.obj)
msvcprt.lib(MSVCP80.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(int)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z) already defined in dcmimage.lib(diyp2img.obj)

(etc)

If I change everything to compile to /MT, I get two errors, linking __argv and __argc, and that only if I explicitly #undef __AFXDLL, so I assume something else is still using /MD to link. What I don't get is, why am I getting these errors when no linkage has changed from my origianl project ?

Any suggestions on how to build DCMTK and link as a dll, or better yet, to get it to work with VC2005, would sure be appreciated. As I've noted, creating an empty MFC app in VC2005 will not link against DCMTK either.

PS FWIW, I moved my project from VC6 to VC2003 this afternoon, and rebuilt DCMTK in a new VC2003 project, also generated by CMake. I got hte same result, a ton of linker errors from DCMTK compiled with /MD against my program, compiled against /MD. I removed DCMTK entirely using #defines, and the rest of my project compiles perfectly well. Is it possible that some of the libraries in the auxilary download, which I am linking against, are not using /MD ? Do I need to recompile libjpeg, etc ?

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#11 Post by Marco Eichelberg »

All support libraries (libtiff, zlib, openssl etc.) are provided in two versions, one compiled with /MT and one compiled with /MTd (the debug version). If you compile DCMTK with /MD, you indeed need to recompile (or disable) all external libraries. I would suggest you start with disabling all external libraries in CMake and try if this solves your problem. If it does, you "only" have to build all support libraries yourself, which is not trivial but not that difficult either.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest