# \[SOLVED\] Undefined reference to QuickView even with ITKVtkGlue added in target\_link\_libraries

**URL:** <https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100>\
**Category:** Beginner Questions\
**Tags:** vtk, itkv5, cmake\
**Created:** [July 9, 2018, 2:31am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100 "2018-07-09T02:31:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![federico](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@federico](https://discourse.itk.org/u/federico)\
**Post date:** [July 9, 2018, 2:31am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/1 "2018-07-09T02:31:36Z")

</div>

Hi,  
I am trying to open and display an image with QuickView, however the linker is unable to find QuickView::AddImage.

```
CMakeFiles/viewer.dir/viewer.cc.o: In function `main':
viewer.cc:(.text+0x12d): undefined reference to `void QuickView::AddImage<itk::Image<short, 3u> >(itk::Image<short, 3u>*, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status

```

In the cmake file I have:

```
cmake_minimum_required(VERSION 3.11)
project(itkTest)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

if (ITKVtkGlue_LOADED)
 find_package(VTK REQUIRED)
 include(${VTK_USE_FILE})
else()
 find_package(ItkVtkGlue REQUIRED)
 include(${ItkVtkGlue_USE_FILE})
 set(Glue ItkVtkGlue)
endif()

add_executable(itkTest itkTest.cc)
target_link_libraries(itkTest ${ITK_LIBRARIES})

add_executable(vtkTest vtkTest.cc)
target_link_libraries(vtkTest ${VTK_LIBRARIES})

add_executable(viewer viewer.cc)
target_link_libraries(viewer ${Glue} ${ITK_LIBRARIES} ${VTK_LIBRARIES})

message(STATUS "${ITK_LIBRARIES}")

```

I have tried ITK, opening an image, and VTK, displaying a cylinder (VTKExamples/Cxx/Rendering/CylinderRenderingProperties), independently and both compile and run fine.

In ITK\_LIBRARIES is included the ITKVtkGlue module (I have compiled the lastest ITK with the Module\_ITKVtkGlue option ON) and according to [this](https://itk.org/Doxygen/html/classQuickView.html) is there where QuickView should be.

I am working on Archlinux with ITK 5.0.0 installed from git (with make install) and VTK 8.1.0 from the repositories. Cmake 3.11.4.

The code:  
#include \<QuickView.h\>  
#include \<itkImageFileReader.h\>

```
int main(int argc, char* argv[])
{
  const std::string inputFilepath("../resources/training_001/mr_PD/training_001_mr_PD.mhd");

  static constexpr unsigned int ImageDimensions = 3;
  using PixelType = short;

  using ImageType = itk::Image<PixelType, ImageDimensions>;
  using ReaderType = itk::ImageFileReader<ImageType>;
    
  ReaderType::Pointer imageReader = ReaderType::New();
  imageReader->SetFileName(inputFilepath);
  imageReader->Update();

  QuickView viewer;
  viewer.AddImage(imageReader->GetOutput());
  viewer.Visualize();

  return 0;
}

```

Thanks!

PD: The else part in the cmake file is no longer necessary because ITKVtkGlue is (from now on) included in ITK, right?

**EDIT:** Maybe if I install vtk from github also? I would like to avoid that, because I prefer to pacman to admin my packages. Maybe a cmake variable about VTK, which ITKVtkGlue needs, is not defined correctly?

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [July 9, 2018, 3:20am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/2 "2018-07-09T03:20:04Z")

</div>

Hi @federico, you are good with VTK 8 from pacman, you just need to build ITKVtkGlue, as you did.

> [@federico](#):
>
> PD: The else part in the cmake file is no longer necessary because ITKVtkGlue is (from now on) included in ITK, right?

Exactly, however a better approach would be to use only the components of ITK that your are using:  
`find_package(ITK REQUIRED COMPONENTS ITKImageIO ITKVtkGlue)`

Try without finding VTK:

```auto
cmake_minimum_required(VERSION 3.11)
project(itkTest)

find_package(ITK REQUIRED COMPONENTS ITKImageIO ITKVtkGlue)
include(${ITK_USE_FILE})

add_executable(viewer viewer.cc)
target_link_libraries(viewer ${ITK_LIBRARIES})

message(STATUS "${ITK_LIBRARIES}")

```

Another thing to try for debug purposes is to use the ITK directly from the build folder, not the one you installed in the system.

---

<div class="post-metadata">

**Author:** ![federico](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@federico](https://discourse.itk.org/u/federico)\
**Post date:** [July 9, 2018, 6:02am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/3 "2018-07-09T06:02:22Z")

</div>

Thanks @phcerdan for your fast answer.

I figure out the problem, (apparently) QuickView does not support 3D images. If I change the dimensions and image filepath to a 2D image, then everything works perfectly.

After little more research, I found [this](https://lorensen.github.io/VTKExamples/site/Cxx/IO/MetaImageReader/) which includes a 3d visualizer. I don’t really understand it, however is a start.

PD: For completeness, and because I didn’t know how to specify a custom directory:

I tried both approaches with a final CMakeLists.txt:  
cmake\_minimum\_required(VERSION 3.11)  
project(itkCode)

```
    message(STATUS "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")

    find_package(ITK REQUIRED COMPONENTS ITKImageIO ITKVtkGlue)
    message(STATUS "ITK_CONFIG=${ITK_CONFIG}")
    include(${ITK_USE_FILE})
    message(STATUS "ITK_USE_FILE: ${ITK_USE_FILE}")

    add_executable(viewer viewer.cc)
    target_link_libraries(viewer ${ITK_LIBRARIES})

    message(STATUS "${ITK_LIBRARIES}")

```

and `cmake -DCMAKE_PREFIX_PATH="/home/federico/ITK-withglue" ..` (where ITKConfig.cmake is) (checked with `make VERBOSE=1`).

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [July 9, 2018, 1:11pm UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/4 "2018-07-09T13:11:50Z")

</div>

Good spotting! You may use `ViewImage` for 3D images, an [example here](https://discourse.itk.org/t/display-3d-image-using-itk-and-vtk/897/3). [ViewImage.h](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Bridge/VtkGlue/include/itkViewImage.h) can be found in the ITKVtkGlue module as well.

```cpp
// Change QuickView.h for itkViewImage.h
#include "itkViewImage.h"
...
reader->Update();
itk::ViewImage<ImageType>::View(reader->GetOutput());

```

---

<div class="post-metadata">

**Author:** ![Sara\_Caffe](https://discourse.itk.org/user_avatar/discourse.itk.org/sara_caffe/32/974_2.png) [@Sara\_Caffe](https://discourse.itk.org/u/Sara_Caffe)\
**Post date:** [October 7, 2019, 4:55am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/5 "2019-10-07T04:55:34Z")

</div>

@federico I still get the same error after enabling ITKVtkGlue flag and adding it to cmakeList.

@phcerdan Thanks for useful comments here,  
I have ground truth files in \*mhd and \*raw files for each patient and the label files has the values between 0-4. However, after running the following code, it is showing a black window:  
`itk::ViewImage<ImageType>::View(reader->GetOutput());`

 ![itkViewOutput](https://discourse.itk.org/uploads/default/original/2X/0/0c9fd04923f614041f4921d2097dd9c969678630.png)

What could be the reason?

- Can we read mhd/raw files by using `itk::Image`, or I should use different data type in ITK?

- I have used the`typedef short PixelType;` data type and `constexpr unsigned int Dimension=3;`, should I change the PixelType here? I am a beginner and a little bit confused. ImageType is defined differently in the codes that I am referring to:

`typedef itk::Image<unsigned char, Dimension> ImageType;`

or

```
typedef float PixelType;
constexpr unsigned int Dimension=3;
using ImageType=itk::Image<PixelType ,Dimension>;
```

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [October 7, 2019, 8:58am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/6 "2019-10-07T08:58:55Z")

</div>

Hi @Sara_Caffe,  
For `itk::ViewImage` use the same `ImageType` you used for reading the image (defined for your `reader`). You don’t have to cast it to float or any other pixel type for the visualization.

This particular viewer wasn’t designed for label images, so maybe you are seeing it black because the label has the value `1`, which is too close to `0` in the `float` range you are using. If you click or hover the mouse in your `black` image you should see a value in the corner. Check if the values are different.

> [@Sara\_Caffe](#):
>
> Can we read mhd/raw files by using `itk::Image` , or I should use different data type in ITK?

It should work straight away if the `PixelType` you use for the reader is appropriate for your data.

Hope it helps.

---

<div class="post-metadata">

**Author:** ![Sara\_Caffe](https://discourse.itk.org/user_avatar/discourse.itk.org/sara_caffe/32/974_2.png) [@Sara\_Caffe](https://discourse.itk.org/u/Sara_Caffe)\
**Post date:** [October 27, 2019, 12:10pm UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/8 "2019-10-27T12:10:30Z")

</div>

Hi again,

I could view the label files (\*.mhd) by using itk::ViewImage, however, it is graylevel images, is there any way to see different values with colors?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [October 27, 2019, 2:02pm UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/9 "2019-10-27T14:02:18Z")

</div>

You could use [LabelToRGB](https://itk.org/Doxygen/html/classitk_1_1LabelToRGBImageFilter.html) filter just before display step.

---

<div class="post-metadata">

**Author:** ![Sara\_Caffe](https://discourse.itk.org/user_avatar/discourse.itk.org/sara_caffe/32/974_2.png) [@Sara\_Caffe](https://discourse.itk.org/u/Sara_Caffe)\
**Post date:** [November 7, 2019, 3:58am UTC](https://discourse.itk.org/t/solved-undefined-reference-to-quickview-even-with-itkvtkglue-added-in-target-link-libraries/1100/10 "2019-11-07T03:58:31Z")

</div>

Thank you very much
