I am testing the 'new' single shared library feature (single DLL) in a windows environment. The usage of inlining in certain classes avoid that it works in Vistual Studio (VS2010 Pro in my case).
I.e., most of the member functions of DcmTagKey are implemented as inlines in the header ('dcmtk/dcmdata/dctagkey.h'). Each usage of DcmTagKey, and that includes the defined default tags like DCM_PatientName, in a project library will pull in the definition of the class member, e.g. DcmTagKey(Uint16, Uint16), into the object file of the class. In a scenario with static sub-libraries in a project the defintion in the dcmtk.lib/dcmtk.dll is not visible. When linking against the dcmtk.lib (export library of the dcmtk.dll) and such a sub-library, the linker will complain with error LNK2005 "already defined in xyz.lib" since it finds two or more definitions.
I used the current git version (from last week). I am on Windows 7 64bit with VS2010 compiling for x64. For now I put the DcmTagKey inlines into the implementation file 'dctagkey.cc' and that works for me (and now). OFCondition and friends have the same issue (althrough indirect by implementing certain member functions in the class body). And I guess there will be many more since a search for 'inline' shows quite some hits.
To reproduce the problem create a 'VC solution' having a static lib (Win32 Static Lib) and an application project (Win 32 Console). Use any of the default tags (e.g. DCM_PatientID) in the static lib and link the application against the static lib and the dcmtk lib (export lib of the dcmtk.dll). The dcmtk is build without apps and with default Cmake settings. None of the support libs have been used.
I hope I made myself clear .
Regards, Yves
single shared library issues with Visual Studio
Moderator: Moderator Team
-
- Posts: 30
- Joined: Fri, 2005-12-02, 17:06
- Location: Germany
-
- DCMTK Developer
- Posts: 120
- Joined: Thu, 2009-11-26, 08:15
Re: single shared library issues with Visual Studio
I'm sorry, but I cannot reproduce this problem.Yves Neumann wrote:To reproduce the problem create a 'VC solution' having a static lib (Win32 Static Lib) and an application project (Win 32 Console). Use any of the default tags (e.g. DCM_PatientID) in the static lib and link the application against the static lib and the dcmtk lib (export lib of the dcmtk.dll). The dcmtk is build without apps and with default Cmake settings. None of the support libs have been used.
With MSVC 2008 building for x86 (I don't have access to some 64bit Windows compiler), I created a static library "lib.lib" and a console application "exe.exe". Both the library and main() execute the following code (additionally, main() calls into the library and does "int i; std::cin >> i;" at its end):
Code: Select all
DcmTagKey k;
std::cout << k.getGroup() << ", " << k.hash() << std::endl;
k = DCM_PatientID;
std::cout << k.getGroup() << ", " << k.hash() << std::endl;
I don't think it should make a difference, but dcmtk.dll was built by MSC6 (I still had this laying around). I will try building dcmtk.dll with MSVC 2008 from current git, too, and see if it makes a difference. But so far, everything works here.
Anything obvious that I did different than you?
Edit: Nope, still works with current git and newer compiler.
-
- Posts: 30
- Joined: Fri, 2005-12-02, 17:06
- Location: Germany
Re: single shared library issues with Visual Studio
Sorry to get back so late on this issue. It turned out that indeed the there was nothing wrong with dcmtk. Somewhere in the chain (by a VS property sheet) it pulled in the header from a NON-shared dcmtk and that was, what screwed up my builds. Including in my test project (to verify). Kind of embarrassing.
Thanks for the support.
Thanks for the support.
Who is online
Users browsing this forum: Google [Bot] and 1 guest