# Installing VTK in Ubuntu 18.04 LTS

**URL:** https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977
**Category:** Support
**Created:** [October 26, 2021, 8:44pm UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977 "2021-10-26T20:44:18Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mn14cat](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@mn14cat](https://discourse.vtk.org/u/mn14cat)
#### Post date: [October 26, 2021, 8:44pm UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/1 "2021-10-26T20:44:18Z")

</div>

Hello all I am trying to downgrade my version of VTK from 6.3.0 to 5.10.1 so that I can use some python utilities (namely pyFoam) however when I try to compile the VTK5.10.1 I get the following error:

CMake Error at CMake/vtkCompilerExtras.cmake:40 (if):  
if given arguments:

```
"cc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

```

Copyright (C) 2017 Free Software Foundation, Inc.

This is free software" " see the source for copying conditions. There is  
NO

warranty" " not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR  
PURPOSE." “VERSION\_GREATER” “4.2.0” “AND” “BUILD\_SHARED\_LIBS” “AND”  
“HAVE\_GCC\_VISIBILITY” “AND” “VTK\_USE\_GCC\_VISIBILITY” “AND” “NOT” “MINGW”  
“AND” “NOT” “CYGWIN”

Unknown arguments specified  
Call Stack (most recent call first):  
CMakeLists.txt:73 (INCLUDE)

I would be greatly appreciative if anyone could please explain the issue and how I would resolve it, thanks in advance

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 26, 2021, 10:56pm UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/2 "2021-10-26T22:56:52Z")

</div>

Older VTK versions detected the compiler version manually. There is a regex in `CMake/vtkCompilerExtras.cmake` that will need expanded to detect the compiler version.

---

<div class="post-metadata">

### Author: ![mn14cat](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@mn14cat](https://discourse.vtk.org/u/mn14cat)
#### Post date: [October 27, 2021, 6:40am UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/3 "2021-10-27T06:40:03Z")

</div>

Thanks for your reply Ben I have been able to locate the

> CMake/vtkCompilerExtras.cmake

file, and I have Identified the REGEX.

```auto
# Now check if we can use visibility to selectively export symbols
  exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE
    _gcc_version_info)
  string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" 
    _gcc_version "${_gcc_version_info}")
  if(NOT _gcc_version)
    string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" 
      _gcc_version "${_gcc_version_info}")
  endif()
  
  # GCC visibility support, on by default and in testing.
  check_cxx_compiler_flag(-fvisibility=hidden HAVE_GCC_VISIBILITY)
  option(VTK_USE_GCC_VISIBILITY "Use GCC visibility support if available." ON)
  mark_as_advanced(VTK_USE_GCC_VISIBILITY)

  if(${_gcc_version} VERSION_GREATER 4.2.0 AND BUILD_SHARED_LIBS
    AND HAVE_GCC_VISIBILITY AND VTK_USE_GCC_VISIBILITY
    AND NOT MINGW AND NOT CYGWIN)
    # Should only be set if GCC is newer than 4.2.0
    set(VTK_ABI_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
  else()
    set(VTK_ABI_CXX_FLAGS "")
  endif()

```

Would you be so kind as to explicitly inform me how I would expand it to detect the compiler version my compiler version is GCC 7.5.0 btw

thanks in advance

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 27, 2021, 2:12pm UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/4 "2021-10-27T14:12:52Z")

</div>

> [@mn14cat](#):
>
> ```auto
> string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" 
> _gcc_version "${_gcc_version_info}")
> 
> ```

This should use `[3-9]` instead of `[34]` (which will work up to GCC 9).

---

<div class="post-metadata">

### Author: ![mn14cat](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@mn14cat](https://discourse.vtk.org/u/mn14cat)
#### Post date: [October 28, 2021, 8:43am UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/5 "2021-10-28T08:43:52Z")

</div>

Hi Ben,

Thank you so much your solution worked I changed both REGEX to 3-9 and it work perfectly I really appreciate your help.

Edit: I was able to run the ccmake configuration and then ran make install command but then got the following error message:

> /home/mn14cat/VTK5.10.1/Common/vtkMath.cxx: In static member function ‘static int vtkMath::GetScalarTypeFittingRange(double, double, double, double)’:  
> /home/mn14cat/VTK5.10.1/Common/vtkMath.cxx:2839:5: error: narrowing conversion of ‘9223372036854775807’ from ‘long int’ to ‘double’ inside { } [-Wnarrowing]  
> };  
> ^  
> /home/mn14cat/VTK5.10.1/Common/vtkMath.cxx:2839:5: error: narrowing conversion of ‘18446744073709551615’ from ‘long unsigned int’ to ‘double’ inside { } [-Wnarrowing]  
> /home/mn14cat/VTK5.10.1/Common/vtkMath.cxx:2839:5: error: narrowing conversion of ‘9223372036854775807’ from ‘long long int’ to ‘double’ inside { } [-Wnarrowing]  
> /home/mn14cat/VTK5.10.1/Common/vtkMath.cxx:2839:5: error: narrowing conversion of ‘18446744073709551615’ from ‘long long unsigned int’ to ‘double’ inside { } [-Wnarrowing]  
> Common/CMakeFiles/vtkCommon.dir/build.make:1354: recipe for target ‘Common/CMakeFiles/vtkCommon.dir/vtkMath.cxx.o’ failed  
> make[2]: \*\*\* [Common/CMakeFiles/vtkCommon.dir/vtkMath.cxx.o] Error 1  
> CMakeFiles/Makefile2:3070: recipe for target ‘Common/CMakeFiles/vtkCommon.dir/all’ failed  
> make[1]: \*\*\* [Common/CMakeFiles/vtkCommon.dir/all] Error 2  
> Makefile:145: recipe for target ‘all’ failed  
> make: \*\*\* [all] Error 2

I have tried to follow your advice on another thread from 2016 with a similar problem where you specified :

“what happens if you turn use -std=c++03 (gnu++14 is the  
default in GCC 6)?”

I have looked in both the vtkMath.cxx and vtkMath.h files to try to implement this change but an not quite sure how to go about doing this?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 28, 2021, 11:52am UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/6 "2021-10-28T11:52:12Z")

</div>

There may be many such errors when compiling such old code with new compilers. Trying to use c++03 is likely to be the easiest path to getting a build. The next best would be using a gcc 4.x if that would work.

---

<div class="post-metadata">

### Author: ![mn14cat](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@mn14cat](https://discourse.vtk.org/u/mn14cat)
#### Post date: [October 28, 2021, 9:32pm UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/7 "2021-10-28T21:32:16Z")

</div>

Hi Ben, really sorry to be a pain but when you suggest

“Trying to use c++03 is likely to be the easiest path to getting a build”.

could you please explain in as much detail how I would go about doing this?

many Thanks

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 29, 2021, 2:40pm UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/8 "2021-10-29T14:40:10Z")

</div>

> [@](#):
>
> “Trying to use c++03 is likely to be the easiest path to getting a build”.

This just means to add the `-std=c++03` flag when compiling VTK-5.10 with g++. In other words, make sure that your CMakeCache.txt contains this:

```
CMAKE_CXX_FLAGS:STRING="-std=c++03"

```

This will allow g++ to accept old code (like VTK-5.10) that doesn’t conform to the newer c++11 or c++14 standards.

---

<div class="post-metadata">

### Author: ![mn14cat](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@mn14cat](https://discourse.vtk.org/u/mn14cat)
#### Post date: [October 30, 2021, 8:48am UTC](https://discourse.vtk.org/t/installing-vtk-in-ubuntu-18-04-lts/6977/9 "2021-10-30T08:48:03Z")

</div>

Thank you very much David I appreciate the help! I was able to sucessfully build build VTK5.10. also thank you Ben.
