0

I have a #define in a separate header file:

#ifndef __sitkConfigure_h
#define __sitkConfigure_h

#define SITK_4D_IMAGES

#endif // __sitkConfigure_h

(full source: https://github.com/kaspermarstal/SimpleITK/blob/8be437486dce85da271576f866393cd54fe0f865/Code/Common/src/sitkConfigure.h.in. The define is managed by a #cmakedefine and turns into #define SITK_4D_IMAGES as expected when cmake is configured.)

As usual the header is included where the config is needed. For example:

#include "sitkConfigure.h"

#ifdef SITK_4D_IMAGES
/** \brief Constructor for 4D images where pixel type can be specified.
 * @{
 */
Image( unsigned int width, unsigned int height, unsigned int depth, unsigned int length, PixelIDValueEnum valueEnum );
/**@}*/
#endif // #ifdef SITK_4D_IMAGES

and

#include "sitkConfigure.h"

#ifdef SITK_4D_IMAGES
Image::Image( unsigned int Width, unsigned int Height, unsigned int Depth, unsigned int Length, PixelIDValueEnum ValueEnum )
  : m_PimpleImage( NULL )
{
  Allocate ( Width, Height, Depth, Length, ValueEnum, 0 );
}
#endif // #ifdef SITK_4D_IMAGES

(full source: https://github.com/kaspermarstal/SimpleITK/blob/8be437486dce85da271576f866393cd54fe0f865/Code/Common/include/sitkImage.h and https://github.com/kaspermarstal/SimpleITK/blob/8be437486dce85da271576f866393cd54fe0f865/Code/Common/src/sitkImage.cxx)

Why are the #ifdef not triggered by the #define in sitkConfigure.h? It is literally driving me nuts. If I put #define SITK_4D_IMAGES directly in the files the #ifdefs are triggered as expected. Further, if I write #define SITK_4D_IMAGES 1 in sitkConfigure.h and #define SITK_4D_IMAGES 2 in the other files, the compiler complains about redefinitions of SITK_4D_IMAGES, so it can clearly see the definition in the files from where the header is included.

Tested on Ubuntu 14.10 with GCC 4.8.9 and Mac OSX Yosemite with Apple Clang 600.0.56. You are most welcome to git clone -b development --single-branch git://github.com/kaspermarstal/SimpleITK.git to reproduce.

Made a minimal example but was unable to reproduce the bug. The issue must be with SimpleITK's build infrastructure. In case anyone is interested it can be downloaded from dropbox.com/s/zlcnqtx32cq4q22/example.zip?dl=0.

Building instructions:

git clone -b development --single-branch git://github.com/kaspermarstal/SimpleITK.git
mkdir build
cd build
cmake ../SimpleITK/SuperBuild
ccmake .

Set SITK_4D_IMAGES to ON, configure, generate and make -j4. The SuperBuild downloads, builds and installs all dependencies.

Kasper Marstal
  • 342
  • 1
  • 15
  • Have you tried to reduce code to minimal reproducible example (like it described [here](http://sscce.org/))? This way you can improve chances to get the answer. Also, please provide building instructions (with dependencies to be installed etc). – Sam Protsenko Mar 10 '15 at 17:56
  • I see at least two possibilities: (1) there's another file `sitkConfigure.h` that is being included instead of the one you think is being included, or (2) there's another header that defines `__sitkConfigure_h`. Note that the name is reserved; you should not be creating names that start with double underscore (or, indeed, a single underscore). – Jonathan Leffler Mar 10 '15 at 18:02
  • @SamProtsenko Building instructions added. Minimal reproducible is a great suggestion. – Kasper Marstal Mar 10 '15 at 20:07
  • @JonathanLeffler Thank you for your suggestions, ruled out (2), (1) will take some digging is ruled out by compiler complaining about redefinitions. As for the double underscore, I have to follow upstream conventions :/ – Kasper Marstal Mar 10 '15 at 20:08
  • Slightly unusual suggestion: can you add `-DSITK_4D_IMAGES=37` on the command line. You should then get a redefinition warning/error where your header is included (since `#define SITK_4D_IMAGES` is not the same as `#define SITK_4D_IMAGES 37`). If that doesn't happen, then you have clear evidence that your header is not functional. Also consider adding `#ifdef __sitkConfigure_h` / `#error sitkConfigure_h pre-defined` / `#endif` to the start of the header. This should tell you if the file is being included more than once, or if the name is generated somehow that you haven't spotted. – Jonathan Leffler Mar 10 '15 at 21:28
  • Or even simply add `#error Header included` at the top of your configuration header... – Jonathan Leffler Mar 10 '15 at 21:28
  • Adding `-DSITK_4D_IMAGES=37` to command line does indeed produce redefinition warnings. Adding `#ifdef __sitkConfigure_h` / `#error sitkConfigure_h pre-defined` / `#endif` throws an errors so file is included more than once. Thank you or your suggestions, will keep digging. – Kasper Marstal Mar 11 '15 at 11:15
  • FYI, made a minimal example but was unable to reproduce the bug. The issue must be with SimpleITK's build infrastructure then. Anyway, in case anyone is interested it can be downloaded from https://www.dropbox.com/s/zlcnqtx32cq4q22/example.zip?dl=0 – Kasper Marstal Mar 11 '15 at 13:46
  • `__sitkConfigure_h` is a [reserved name](http://stackoverflow.com/q/228783/981959) and should not be used – Jonathan Wakely Mar 11 '15 at 16:12
  • Thanks for the info. However, as previously discussed, that is upstream code. – Kasper Marstal Mar 11 '15 at 16:29

1 Answers1

1

The #ifdefs where handled correctly by the compiler. The issue was related to the use of SWIG for wrapping the interface in Python/Java/R/Ruby/Octave/Tcl/Lua/C#. The defines were not passed to SWIG which therefore did not compile what was inside the #ifdef. Adding %include "sitkConfigure.h" to the SWIG .i file fixed the problem.

Kasper Marstal
  • 342
  • 1
  • 15