# Slicer CLI module compilation error: undefined reference to \`itk::GeometryUtilities

**URL:** <https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100>\
**Category:** Support\
**Created:** [February 16, 2018, 5:24pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100 "2018-02-16T17:24:53Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 16, 2018, 5:24pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/1 "2018-02-16T17:24:53Z")

</div>

Hellow friends,

I’m very much a beginner in the 3DSlicer development world. I’m struggling with a compilation problem.  
I created a CLI module through Slicer “Extension Manager” and started to change it according to my goals.  
I then go to Cmake-gui to generate and configure. And sounds that everything went well except for two **warnings** :

```auto
CMake Warning (dev) at /home/leonardo/General_Sources/Slicer/CMake/SlicerMacroExtractRepositoryInfo.cmake:95 (message):
  Skipping repository info extraction: directory
  [/home/leonardo/Desktop/Modulos-Source/Modulos_to_Slicer/CSIM] is not a
  GIT, SVN or CVS checkout
Call Stack (most recent call first):
  /home/leonardo/General_Sources/Slicer/Extensions/CMake/SlicerExtensionPackageAndUploadTarget.cmake:122 (SlicerMacroExtractRepositoryInfo)
  /home/leonardo/General_Sources/Slicer/CMake/SlicerExtensionCPack.cmake:219 (include)
  CMakeLists.txt:27 (include)
This warning is for project developers. Use -Wno-dev to suppress it.

Furthermore **in the QT compilation step** it happen as follows:

1) When I creat and execute my CLI module **directly** ( **Without Extension Wizard** ):

I use the following **CMakeLists.txt** :

#####################################
#-----------------------------------------------------------------------------
project(TextureProcessingV8)

cmake_minimum_required( VERSION 2.6 )

set(MODULE_NAME TextureProcessing)

if(NOT Slicer_SOURCE_DIR)
  find_package(Slicer REQUIRED)
  include(${Slicer_USE_FILE})
endif()

#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
  NAME ${MODULE_NAME}
  #LOGO_HEADER ${Slicer_SOURCE_DIR}/Resources/ITKLogo.h
  ADDITIONAL_SRCS
    Plot/HistogramPlot.cxx
    Percents/PercentileCalc.cxx
    Features/HistoFeat.cxx
    CoocurrenceFeat/CoocurrenceFeat.cxx
    ShapeFeatures/ShapeFeat.cxx
    RunLengthFeat/RunLengthFeat.cxx
    Normalization/Normalize.cxx
    Gradient/GradientFeat.cxx		 	

  TARGET_LIBRARIES ${ITK_LIBRARIES}
  )

#add_subdirectory(Texture)

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()

########################################################

**No ERROR Occurred AT ALL**

2) When I insert the same CLI source code inside the **EXTENSION WIZARD** Pre-built files:

I use the following CMakeLists.txt for the **MODULE**
##############################################

#-----------------------------------------------------------------------------
set(MODULE_NAME TextureProcessing)

#-----------------------------------------------------------------------------

#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})

#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
  ITKIOImageBase
  ITKSmoothing
  )
find_package(ITK 4.6 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})

#-----------------------------------------------------------------------------
set(MODULE_INCLUDE_DIRECTORIES
  )

set(MODULE_SRCS
  )

set(MODULE_TARGET_LIBRARIES
  ${ITK_LIBRARIES}
  )

#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
  NAME ${MODULE_NAME}
  TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES}
  INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
  ADDITIONAL_SRCS ${MODULE_SRCS}
Plot/HistogramPlot.cxx
    Percents/PercentileCalc.cxx
    Features/HistoFeat.cxx
    CoocurrenceFeat/CoocurrenceFeat.cxx
    ShapeFeatures/ShapeFeat.cxx
    RunLengthFeat/RunLengthFeat.cxx
    Normalization/Normalize.cxx
    Gradient/GradientFeat.cxx
  )

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()

#############################################################

And the following **CMakeLists.txt for the EXTENSION** :

The following **Errors OCCUR** :

**error: undefined reference to `itk::GeometryUtilities::HyperSphereRadiusFromVolume(int, double)'**
 **/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:372:**

**error: undefined reference to `itk::GeometryUtilities::HyperSpherePerimeter(int, double)'**
 **/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:373:**

**error: undefined reference to `itk::GeometryUtilities::HyperSphereRadiusFromVolume(int, double)'**
 **/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:372:**

**error: undefined reference to `itk::GeometryUtilities::HyperSpherePerimeter(int, double)'**
 **/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:373:'** 

I really can't find the solution.
I appreciate any contributions!!!!

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 16, 2018, 7:15pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/2 "2018-02-16T19:15:15Z")

</div>

This is just a warning that CMake cannot automatically detect your source code repository URL. You can safely ignore it.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 16, 2018, 8:41pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/3 "2018-02-16T20:41:12Z")

</div>

To fix the undefined reference error mentioned in the title, make sure you have included the ITK header file where GeometryUtilities is declared in.

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 16, 2018, 8:56pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/4 "2018-02-16T20:56:35Z")

</div>

Auh… Thank you very much for the feedback.  
Unfortunately I didn’t finish my question before submitting the post. I’m  
sorry.

But the final part of the problem I’m struggling is error:  
‘Undefined reference’

I’ll post the complete error log soon as I get the chance.

Thanks a lot for now.

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 26, 2018, 4:44pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/5 "2018-02-26T16:44:42Z")

</div>

@lassoan, this is the complete version of my question. Would love to hear any help.

I’m very much a beginner in the 3DSlicer development world. I’m struggling with a compilation problem.  
I created a CLI module through Slicer “Extension Manager” and started to change it according to my goals.  
I then go to Cmake-gui to generate and configure. And sounds that everything went well except for two **warnings** :

```auto
CMake Warning (dev) at /home/leonardo/General_Sources/Slicer/CMake/SlicerMacroExtractRepositoryInfo.cmake:95 (message):
  Skipping repository info extraction: directory
  [/home/leonardo/Desktop/Modulos-Source/Modulos_to_Slicer/CSIM] is not a
  GIT, SVN or CVS checkout
Call Stack (most recent call first):
  /home/leonardo/General_Sources/Slicer/Extensions/CMake/SlicerExtensionPackageAndUploadTarget.cmake:122 (SlicerMacroExtractRepositoryInfo)
  /home/leonardo/General_Sources/Slicer/CMake/SlicerExtensionCPack.cmake:219 (include)
  CMakeLists.txt:27 (include)
This warning is for project developers. Use -Wno-dev to suppress it.

```

Furthermore **in the QT compilation step** it happen as follows:

1. When I creat and execute my CLI module **directly** ( **Without Extension Wizard** ):

I use the following **CMakeLists.txt** :

```auto
#####################################
#-----------------------------------------------------------------------------
project(TextureProcessingV8)

cmake_minimum_required( VERSION 2.6 )

set(MODULE_NAME TextureProcessing)

if(NOT Slicer_SOURCE_DIR)
  find_package(Slicer REQUIRED)
  include(${Slicer_USE_FILE})
endif()

#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
  NAME ${MODULE_NAME}
  #LOGO_HEADER ${Slicer_SOURCE_DIR}/Resources/ITKLogo.h
  ADDITIONAL_SRCS
    Plot/HistogramPlot.cxx
    Percents/PercentileCalc.cxx
    Features/HistoFeat.cxx
    CoocurrenceFeat/CoocurrenceFeat.cxx
    ShapeFeatures/ShapeFeat.cxx
    RunLengthFeat/RunLengthFeat.cxx
    Normalization/Normalize.cxx
    Gradient/GradientFeat.cxx		 	

  TARGET_LIBRARIES ${ITK_LIBRARIES}
  )

#add_subdirectory(Texture)

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()

########################################################

```

**No ERROR Occurred AT ALL**

1. When I insert the same CLI source code inside the **EXTENSION WIZARD** Pre-built files:

I use the following CMakeLists.txt for the **MODULE**

```auto
##############################################

#-----------------------------------------------------------------------------
set(MODULE_NAME TextureProcessing)

#-----------------------------------------------------------------------------

#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})

#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
  ITKIOImageBase
  ITKSmoothing
  )
find_package(ITK 4.6 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})

#-----------------------------------------------------------------------------
set(MODULE_INCLUDE_DIRECTORIES
  )

set(MODULE_SRCS
  )

set(MODULE_TARGET_LIBRARIES
  ${ITK_LIBRARIES}
  )

#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
  NAME ${MODULE_NAME}
  TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES}
  INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
  ADDITIONAL_SRCS ${MODULE_SRCS}
Plot/HistogramPlot.cxx
    Percents/PercentileCalc.cxx
    Features/HistoFeat.cxx
    CoocurrenceFeat/CoocurrenceFeat.cxx
    ShapeFeatures/ShapeFeat.cxx
    RunLengthFeat/RunLengthFeat.cxx
    Normalization/Normalize.cxx
    Gradient/GradientFeat.cxx
  )

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()

#############################################################

```

And the following **CMakeLists.txt for the EXTENSION** :

```auto
cmake_minimum_required(VERSION 3.5)

project(TextureAnalysis)

#-----------------------------------------------------------------------------
# Extension meta-information
set(EXTENSION_HOMEPAGE "http://slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/CSIM")
set(EXTENSION_CATEGORY "Examples")
set(EXTENSION_CONTRIBUTORS "John Doe (AnyWare Corp.)")
set(EXTENSION_DESCRIPTION "This is an example of a simple extension")
set(EXTENSION_ICONURL "http://www.example.com/Slicer/Extensions/CSIM.png")
set(EXTENSION_SCREENSHOTURLS "http://www.example.com/Slicer/Extensions/CSIM/Screenshots/1.png")
set(EXTENSION_DEPENDS "NA") # Specified as a space separated string, a list or 'NA' if any

#-----------------------------------------------------------------------------
# Extension dependencies
find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})

#-----------------------------------------------------------------------------
# Extension modules
add_subdirectory(TextureProcessing)
## NEXT_MODULE

#-----------------------------------------------------------------------------
include(${Slicer_EXTENSION_GENERATE_CONFIG})
include(${Slicer_EXTENSION_CPACK})

```

The following **Errors OCCURED** :

**error: undefined reference to `itk::GeometryUtilities::HyperSphereRadiusFromVolume(int, double)’**  
/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:372:

**error: undefined reference to `itk::GeometryUtilities::HyperSpherePerimeter(int, double)’**  
/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:373:

**error: undefined reference to `itk::GeometryUtilities::HyperSphereRadiusFromVolume(int, double)’**  
/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:372:

**error: undefined reference to `itk::GeometryUtilities::HyperSpherePerimeter(int, double)’**  
/usr/local/Slicer/ITKv4/Modules/Filtering/LabelMap/include/itkShapeLabelMapFilter.hxx:373:’

I really can’t find the solution.  
I appreciate any contributions!!!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 26, 2018, 4:58pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/6 "2018-02-26T16:58:15Z")

</div>

Please upload your extension to github and post the link here so that I can have a look. Thanks!

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 26, 2018, 4:59pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/7 "2018-02-26T16:59:56Z")

</div>

Ok. Thank you very much. I’ll take a time… once I’m also starting with git and everything… But I’ll do it right away.  
Thank you!

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 26, 2018, 8:43pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/8 "2018-02-26T20:43:47Z")

</div>

Dr. Lasso,

I just added you to my github project. Hope you can check it out!

Thank you very much!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 27, 2018, 2:45pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/9 "2018-02-27T14:45:40Z")

</div>

The solution was to adjust the CMakeLists.txt:

- add `ITKLabelMap` to `${PROJECT_NAME}_ITK_COMPONENTS`
- add `${CMAKE_CURRENT_SOURCE_DIR}` to `MODULE_INCLUDE_DIRECTORIES`
- add `${SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES}` to `target_link_libraries(${CLP}Test ${CLP}Lib ...)` (probably old version of Extension Wizard was used, that’s why it was missing)

See details here:  
[https://github.com/MachadoLF/CLI-Module---Texture-Feature-Extractor/pull/1](https://github.com/MachadoLF/CLI-Module---Texture-Feature-Extractor/pull/1)

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 27, 2018, 5:25pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/10 "2018-02-27T17:25:12Z")

</div>

## Thank you very much, Dr. Lasso.

It completely fixed my problems!!!

I tested change by change and saw that the **first one** (add ITKLabelMap to ${PROJECT\_NAME}\_ITK\_COMPONENTS) had already solved **ALL** my issues without even doing the additional ones.

In this case, is it **necessary** to make the additional changes you mentioned? Or is it only something like _good programming practices_?

What do you think?

Thanks a lot for your feedback!!!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 27, 2018, 6:01pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/11 "2018-02-27T18:01:45Z")

</div>

Most often, header files are in a single directory, as when you have files that are not tightly linked, you compile them as separate libraries.

In some cases, you use relative paths, but then the usually you add the base folder to the list of include directories and you define paths relative to that (and never use `./` or `../` in the `#include` directive).

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 27, 2018, 6:04pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/12 "2018-02-27T18:04:30Z")

</div>

> [@lassoan](#):
>
> add ${CMAKE\_CURRENT\_SOURCE\_DIR} to MODULE\_INCLUDE\_DIRECTORIES

Your last comment is related to this change?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 27, 2018, 7:58pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/13 "2018-02-27T19:58:42Z")

</div>

Yes. It adds the source code top-level directory to the include paths. So, if you need to refer to a header file then you can always do that relative to this top-level directory and you don’t need to reach it by prepending `../../` to the header file name.

---

<div class="post-metadata">

**Author:** ![MachadoL](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/machadol/32/3372_2.png) [@MachadoL](https://discourse.slicer.org/u/MachadoL)\
**Post date:** [February 27, 2018, 8:08pm UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/14 "2018-02-27T20:08:59Z")

</div>

Ok! I got it! Thank you very much. Everything worked out nice and smoothly. And thanks for the tips with programming.

Thanks again!

Machado, L.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 25, 2020, 6:21am UTC](https://discourse.slicer.org/t/slicer-cli-module-compilation-error-undefined-reference-to-itk-geometryutilities/2100/15 "2020-09-25T06:21:02Z")

</div>

A post was merged into an existing topic: [Error: failed to read input surface\ compiled CLI module](https://discourse.slicer.org/t/error-failed-to-read-input-surface-compiled-cli-module/13603/2)
