3

I downloaded source of GDCM 2.4.1 and used CMake 2.8.12.1 and Visual Studio 2010 to build the libraries. I want to use GDCM in my C++ project. Unfortunately, it seems that after building the GDCM solution with VS, there are only the lib-files in the bin folder, but no typical "include" folder with the header files, what I usually expect. Thus, I can't integrate GDCM libaries in my own project (I tried to use FindPackage(GDCM) in my own CMakeproject, but header files can't be found).

I do not want to copy the header files manually or target the source directory of GDCM. Does anybody know help?

MichaelXanadu
  • 505
  • 1
  • 10
  • 25
  • Hm, this seems very unusal to me. I work a lot with multiple C++ libaries. Usually the build process generates a new folder "include" and puts all needed header files into it. Targeting the source folder is suboptimal, because you also target non-header files...Also this is not the way described in the official GDCM documentation. They recommend to use FindPackage(GDCM), which does not work for me because the header files are missing. – MichaelXanadu Jan 14 '14 at 14:48
  • You are not supposed to have the build folder the same as the source folder. And with GDCM (and other similar libraries based on CMake) I generally do not build the INSTALL project instead build the ALL_BUILD target and when I build my own CMake based application I set GDCM_DIR to the root folder which I built GDCM in. – drescherjm Jan 14 '14 at 16:41

2 Answers2

2

I found out that the problem has something to do with VTK, I also use the this library in my project. So I need to enable "GDCM_USE_VTK" in CMake of GDCM. That option leads to a compiler error when I try to build the "INSTALL" subproject in the GDCM solution:

CMake Error at cmake_install.cmake:31 (FILE): file INSTALL cannot find "D:/Libs/VTK_5.6.0/BIN/bin/vtkCommon.dll".

I took a look in the VTK directory and found out that the path mentioned above does not exists. Instead the dll is located in:

D:\Libs\VTK_5.6.0\BIN\bin\Release\vtkCommon.dll or D:\Libs\VTK_5.6.0\BIN\bin\Debug\vtkCommon.dll

That means GDCM solution does not know the dll is located in a special debug or release folder. If I disable "GDCM_USE_VTK" everything works fine and all files will be copied to the target folder. But I do need the VTK dll. Any thoughts?

Michael

MichaelXanadu
  • 505
  • 1
  • 10
  • 25
  • The install project is supposed to install to C:\Program Files\VTK unless you have changed the CMAKE_INSTALL_PREFIX and you have permission to install there. Although again I will caution using that since using it locks you into using only Debug or Release for all of your code (not both) if you use BUILD_SHARED. The reason is you can not safely use the Debug heap and Release heap in a single application. This will lead to random crashes when allocating or deallocating memory. – drescherjm Jan 15 '14 at 13:54
  • Also why are you using a current version of GDCM with a several year old version of VTK? – drescherjm Jan 15 '14 at 13:56
  • Thank you for your hint. I'm not using BUILD_SHARED, so I think I will not have problems. I will also try to specify the CMAKE_INSTALL_PREFIX of VTK. The reason for old VTK and new GDCM is that the I currently update my program to newer libaries, starting with GDCM. Do you think it could be a problem using new GDCM and old VTK (temporarily)? – MichaelXanadu Jan 15 '14 at 14:10
  • If it is asking for .dlls you have build shared enabled at least for VTK. – drescherjm Jan 15 '14 at 14:15
  • I have not tried that old of VTK with recent GDCM. Currently I do use GDCM-2.4.X with VTK-5.10.0 on both Visual Studio 2010 and Visual Studio 2012 both in the x64 configuration. I develop in VS2010 but build the targets I distribute under VS2012. In all cases I disable BUILD_SHARED and use the procedure I described in my first post. – drescherjm Jan 15 '14 at 14:20
  • The procedure you described above does not work for me. It causes the error I mentioned in my first post. How do you link the GDCM libraries in your project's CMakeLists.txt? I did it the offical way. See "How do I use GDCM in my project ?" here: http://gdcm.sourceforge.net/wiki/index.php/Common_questions – MichaelXanadu Jan 15 '14 at 14:42
  • I use basically the same way + some setting of CMake variables. By default CMake will not find GDCM so I set GDCM_DIR. I used to manually do that on the first configure from cmake-gui but now I do this in a more scripted way with a batch file that sets environment variables + run cmake the first time from that environment and code in my applications CMake scripts to read the environment variables and set GDCM_DIR. Same with VTK_DIR, ITK_DIR, BOOST_ROOT DCMTK_DIR ... – drescherjm Jan 15 '14 at 15:16
  • Hmm. One thing that I do that the example on the sourceforge site does not is include(${GDCM_USE_FILE}) after finding GDCM – drescherjm Jan 15 '14 at 15:21
  • I tried include(${GDCM_USE_FILE}), this time I get some LNK2018 linker errors instead of the "missing header" errors. I checked some project properties, both GDCM project and my own project use same charcter set and same runtime library (MD). But I think we're coming closer the the problem. Any thoughts? – MichaelXanadu Jan 15 '14 at 16:59
  • E.G: 2>iisDicomReaderGDCM.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall gdcm::Sorter::~Sorter(void)" (??1Sorter@gdcm@@UAE@XZ) referenced in function "public: virtual __thiscall gdcm::IPPSorter::~IPPSorter(void)" (??1IPPSorter@gdcm@@UAE@XZ) – MichaelXanadu Jan 15 '14 at 17:53
  • OR: vtkgdcm.lib(vtkGDCMImageReader.obj) : error LNK2019: unresolved external symbol "public: enum gdcm::PixelFormat::ScalarType __thiscall gdcm::PixelFormat::GetScalarType(void)const " (?GetScalarType@PixelFormat@gdcm@@QBE?AW4ScalarType@12@XZ) referenced in function "public: __thiscall gdcm::PixelFormat::operator enum gdcm::PixelFormat::ScalarType(void)const " (??BPixelFormat@gdcm@@QBE?AW4ScalarType@01@XZ) – MichaelXanadu Jan 15 '14 at 17:54
  • Both seem to point at missing gdcmMSFF. In an application that uses gdcm + vtk I am using the following in a target_link_libaraies(gdcmMSFF vtkgdcm vtkCommon) – drescherjm Jan 15 '14 at 18:19
  • Unfortunatelly there are still linker errors afterwards. For example: – MichaelXanadu Jan 15 '14 at 18:41
  • error LNK2019: unresolved external symbol "protected: unsigned int __thiscall gdcm::Directory::Explore(class std::basic_string,class std::allocator > const &,bool)" (?Explore@Directory@gdcm@@IAEIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) referenced in function "public: unsigned int __thiscall gdcm::Directory::Load(class std::basic_string,class std::allocator > const &,bool)" (?Load@Directory@gdcm@@QAEIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) – MichaelXanadu Jan 15 '14 at 18:42
  • Do you think I have to target ALL gdcm libraries? – MichaelXanadu Jan 15 '14 at 18:43
  • gdcm::Directory is in gdcmCommon. I would add that one as well. You may have to include more gdcm libraries in your target_link_libraries. – drescherjm Jan 15 '14 at 18:45
  • Ok, I included all(!) libraries, now there's only one single final linker error left: – MichaelXanadu Jan 15 '14 at 18:53
  • gdcmMSFF.lib(gdcmUIDGenerator.obj) : error LNK2019: unresolved external symbol __imp__UuidCreate@4 referenced in function "protected: static bool __cdecl gdcm::UIDGenerator::GenerateUUID(unsigned char *)" (?GenerateUUID@UIDGenerator@gdcm@@KA_NPAE@Z) – MichaelXanadu Jan 15 '14 at 18:54
  • Try adding Rpcrt4 to your target_link_libraries. I have that in 1 of my projects. – drescherjm Jan 15 '14 at 19:04
0

For anyone who ever touches the same problem, here's the final solution. Build "ALL_BUILD" in the GDCM solution, then integrate GDCM libs in your CMakeLists.txt the following way:

FIND_PACKAGE(GDCM REQUIRED)
    IF(GDCM_FOUND)
        INCLUDE(${GDCM_USE_FILE})
        SET(GDCM_LIBRARIES 
            gdcmcharls
            gdcmCommon
            gdcmDICT
            gdcmDSED
            gdcmexpat
            gdcmgetopt
            gdcmIOD
            gdcmjpeg12
            gdcmjpeg16
            gdcmjpeg8
            gdcmMEXD
            gdcmMSFF
            gdcmopenjpeg
            gdcmzlib
            socketxx
            vtkgdcm
            Rpcrt4)
    ELSE(GDCM_FOUND)
        MESSAGE(FATAL_ERROR "Cannot find GDCM, did you set GDCM_DIR?")
    ENDIF(GDCM_FOUND)
malat
  • 12,152
  • 13
  • 89
  • 158
MichaelXanadu
  • 505
  • 1
  • 10
  • 25