Installing VTK in Ubuntu 18.04 LTS

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

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.

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

CMake/vtkCompilerExtras.cmake

file, and I have Identified the REGEX.

# 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

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

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?

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.

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

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.

1 Like

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