[Insight-developers] gdcm and stdint.h

Bill Hoffman bill.hoffman at kitware.com
Wed Feb 2 13:33:29 EST 2011


In the building of modular ITK, we are running into trouble with gdcm 
and stdint.h.


The trouble comes from gdcmTypes.h here:


#if defined(__BORLANDC__) && (__BORLANDC__ < 0x0560) || defined(__MINGW32__)
typedef  signed char         int8_t;
typedef  signed short        int16_t;
typedef  signed int          int32_t;
typedef  unsigned char       uint8_t;
typedef  unsigned short      uint16_t;
typedef  unsigned int        uint32_t;
typedef  unsigned __int64    uint64_t;
#elif defined(_MSC_VER)
#include "stdint.h"
#else
#error "Sorry your plateform is not supported"
#endif // defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 
0x0560)  || defined(__MINGW32__)
#endif // GDCM_HAVE_INTTYPES_H
#endif // GDCM_HAVE_STDINT_H


Basically the above code does this:

#ifdef HAS_STDINT
#include "stdint.h"
#else
... lots of confusing stuff
# if MSVC
# include "stdint.h"  !!!
# endif
#endif

So, if a cmake try compile figures out the system does not have 
stdint.h, and you are using the microsoft compiler, then you include 
stdint.h!  Sounds crazy... This works because there is a stdint.h in 
gdcm Utilities/C99 there is a copy of stdint.h.   This is activated by 
cmake in itkIncludeDirectories.cmake

   if(MSVC)
     set(ITK_INCLUDE_DIRS_BUILD_TREE ${ITK_INCLUDE_DIRS_BUILD_TREE}
       ${ITK_SOURCE_DIR}/Utilities/gdcm/Utilities/C99
     )
   endif(MSVC)


Why was the C99 introduced in gdcm?  Seems like this code:

#if defined(__BORLANDC__) && (__BORLANDC__ < 0x0560) || defined(__MINGW32__)
typedef  signed char         int8_t;
typedef  signed short        int16_t;
...

Would work much better.  Or if you really want the header you could do 
something like this:
#ifdef HAVE_STDINT_H
# include <stdint.h>
#else
# include <gdcmC99/stdint.h>
#endif

Then put gdcmC99 as a sub-directory of a -I that all gdcm builds need.


That would be:

#ifdef HAS_STDINT_H
#include "stdint.h"
#else
# // define what we need from stdint.h
#endif

No extra -I needed for compiling against gdcm with one compiler...

-Bill


More information about the Insight-developers mailing list