Skip to content

Module vtkIOImage fails to build when SMP backend set to TBB

I am running into a compilation error on macOS with TBB enabled.

On my mac, I have installed Intel's Thread Building Blocks (TBB) via homebrew.

brew install tbb

It is installed under /usr/local. I also have imagemagick installed, which depend's on brew's jpeg package, hence a libjpeg library is installed in /usr/local as well.

When configuring VTK to use TBB as the SMP backend (e.g., cmake -G Ninja -DVTK_SMP_IMPLEMENTATION_TYPE:STRING=TBB <src>), I get a build error in vtkIOImage:

In file included from /Users/cory.quammen/src/VTK/IO/Image/vtkJPEGReader.cxx:25:
In file included from ThirdParty/jpeg/vtk_jpeg.h:32:
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:71:9: error: unknown type name 'JSAMPLE'
typedef JSAMPLE *JSAMPROW;      /* ptr to one image row of pixel samples. */
        ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:660:3: error: unknown type name 'JSAMPLE'
  JSAMPLE *sample_range_limit;  /* table for fast range-limiting */
  ^
/Users/cory.quammen/src/VTK/IO/Image/vtkJPEGReader.cxx:179:3: error: use of undeclared identifier 'JPEG_LIB_VERSION'; did you mean 'JMSG_VERSION'?
  jpeg_create_decompress(&cinfo);
  ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:906:36: note: expanded from macro 'jpeg_create_decompress'
    jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
                                   ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:139:10: note: 'JMSG_VERSION' declared here
JMESSAGE(JMSG_VERSION, JVERSION)
         ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:39:33: note: expanded from macro 'JMESSAGE'
#define JMESSAGE(code,string)   code ,
                                ^
/Users/cory.quammen/src/VTK/IO/Image/vtkJPEGReader.cxx:261:3: error: use of undeclared identifier 'JPEG_LIB_VERSION'; did you mean 'JMSG_VERSION'?
  jpeg_create_decompress(&cinfo);
  ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:906:36: note: expanded from macro 'jpeg_create_decompress'
    jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
                                   ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:139:10: note: 'JMSG_VERSION' declared here
JMESSAGE(JMSG_VERSION, JVERSION)
         ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:39:33: note: expanded from macro 'JMESSAGE'
#define JMESSAGE(code,string)   code ,
                                ^
/Users/cory.quammen/src/VTK/IO/Image/vtkJPEGReader.cxx:293:22: error: assigning to 'JSAMPROW' (aka 'int *') from incompatible type 'unsigned char *'
    row_pointers[ui] = tempImage + rowbytes*ui;
                     ^ ~~~~~~~~~~~~~~~~~~~~~~~
/Users/cory.quammen/src/VTK/IO/Image/vtkJPEGReader.cxx:447:3: error: use of undeclared identifier 'JPEG_LIB_VERSION'; did you mean 'JMSG_VERSION'?
  jpeg_create_decompress(&cinfo);
  ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:906:36: note: expanded from macro 'jpeg_create_decompress'
    jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
                                   ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:139:10: note: 'JMSG_VERSION' declared here
JMESSAGE(JMSG_VERSION, JVERSION)
         ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:39:33: note: expanded from macro 'JMESSAGE'
#define JMESSAGE(code,string)   code ,
                                ^
6 errors generated.
[632/648] Building CXX object IO/Image/CMakeFiles/vtkIOImage.dir/vtkJPEGWriter.cxx.o
FAILED: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -DVTK_IN_VTK -DvtkIOImage_EXPORTS -IIO/Image -I/Users/cory.quammen/src/VTK/IO/Image -ICommon/Core -I/Users/cory.quammen/src/VTK/Common/Core -I/usr/local/include -IUtilities/KWIML -I/Users/cory.quammen/src/VTK/Utilities/KWIML -IUtilities/KWSys -I/Users/cory.quammen/src/VTK/Utilities/KWSys -IThirdParty/utf8 -I/Users/cory.quammen/src/VTK/ThirdParty/utf8 -ICommon/DataModel -I/Users/cory.quammen/src/VTK/Common/DataModel -ICommon/Math -I/Users/cory.quammen/src/VTK/Common/Math -ICommon/Misc -I/Users/cory.quammen/src/VTK/Common/Misc -ICommon/System -I/Users/cory.quammen/src/VTK/Common/System -ICommon/Transforms -I/Users/cory.quammen/src/VTK/Common/Transforms -ICommon/ExecutionModel -I/Users/cory.quammen/src/VTK/Common/ExecutionModel -IUtilities/DICOMParser -I/Users/cory.quammen/src/VTK/Utilities/DICOMParser -IUtilities/MetaIO/vtkmetaio -IUtilities/MetaIO -I/Users/cory.quammen/src/VTK/Utilities/MetaIO -IThirdParty/zlib -I/Users/cory.quammen/src/VTK/ThirdParty/zlib -IThirdParty/jpeg/vtkjpeg -IThirdParty/jpeg -I/Users/cory.quammen/src/VTK/ThirdParty/jpeg -IThirdParty/png -I/Users/cory.quammen/src/VTK/ThirdParty/png -IThirdParty/tiff/vtktiff/libtiff -IThirdParty/tiff -I/Users/cory.quammen/src/VTK/ThirdParty/tiff -IThirdParty/png/vtkpng -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fPIC -fvisibility=hidden   -std=c++11 -MD -MT IO/Image/CMakeFiles/vtkIOImage.dir/vtkJPEGWriter.cxx.o -MF IO/Image/CMakeFiles/vtkIOImage.dir/vtkJPEGWriter.cxx.o.d -o IO/Image/CMakeFiles/vtkIOImage.dir/vtkJPEGWriter.cxx.o -c /Users/cory.quammen/src/VTK/IO/Image/vtkJPEGWriter.cxx
In file included from /Users/cory.quammen/src/VTK/IO/Image/vtkJPEGWriter.cxx:27:
In file included from ThirdParty/jpeg/vtk_jpeg.h:32:
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:71:9: error: unknown type name 'JSAMPLE'
typedef JSAMPLE *JSAMPROW;      /* ptr to one image row of pixel samples. */
        ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:660:3: error: unknown type name 'JSAMPLE'
  JSAMPLE *sample_range_limit;  /* table for fast range-limiting */
  ^
/Users/cory.quammen/src/VTK/IO/Image/vtkJPEGWriter.cxx:283:3: error: use of undeclared identifier 'JPEG_LIB_VERSION'; did you mean 'JMSG_VERSION'?
  jpeg_create_compress(&cinfo);
  ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jpeglib.h:903:34: note: expanded from macro 'jpeg_create_compress'
    jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
                                 ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:139:10: note: 'JMSG_VERSION' declared here
JMESSAGE(JMSG_VERSION, JVERSION)
         ^
/Users/cory.quammen/src/VTK/ThirdParty/jpeg/vtkjpeg/jerror.h:39:33: note: expanded from macro 'JMESSAGE'
#define JMESSAGE(code,string)   code ,
                                ^
3 errors generated.

The problem is that the include path for TBB appears before the include paths for the third party jpeg in VTK. The compiler is finding the libjpeg under /usr/include which is configured differently than VTK's, hence the compilation error.