Issues building VTK with TK bindings

I have been trying for hours now to set up and build VTK with the TK integration without success. I’m still stuck on configuring Cmake with the following warnings and issues.

I’m building on Windows (10) with TDM-MinGW which detects fine. I have both tried to install IronTCL and to use conda tk but get the warnings and errors below. I believe the main issue is the error “target_include_directories called with incorrect number of arguments” which I think refers to the tcl/tk include paths. But I have no idea how to resolve it and would appreciate any help or ideas.

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
  The package name passed to `find_package_handle_standard_args` (Tclsh) does
  not match the name of the calling package (TCL).  This can lead to problems
  in calling code that expects `find_package` result variables (e.g.,
  `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.17/Modules/FindTclsh.cmake:95 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMake/FindTCL.cmake:35 (INCLUDE)
  Rendering/Tk/CMakeLists.txt:2 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

Found Tclsh: C:\Miniconda3\pkgs\tk-8.6.8-hfa6e2cd_0\Library\bin\tclsh.exe (found version "8.6")
Found TCL: C:\Miniconda3\pkgs\tk-8.6.8-hfa6e2cd_0\Library\lib
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
  The package name passed to `find_package_handle_standard_args` (TCLTK) does
  not match the name of the calling package (TCL).  This can lead to problems
  in calling code that expects `find_package` result variables (e.g.,
  `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  CMake/FindTCL.cmake:186 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  Rendering/Tk/CMakeLists.txt:2 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

Found TCLTK: C:\Miniconda3\pkgs\tk-8.6.8-hfa6e2cd_0\Library\lib
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
  The package name passed to `find_package_handle_standard_args` (TK) does
  not match the name of the calling package (TCL).  This can lead to problems
  in calling code that expects `find_package` result variables (e.g.,
  `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  CMake/FindTCL.cmake:189 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  Rendering/Tk/CMakeLists.txt:2 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

Found TK: C:\Miniconda3\pkgs\tk-8.6.8-hfa6e2cd_0\Library\lib
CMake Error at CMake/vtkModule.cmake:1398 (target_include_directories):
  target_include_directories called with incorrect number of arguments
Call Stack (most recent call first):
  Rendering/Tk/CMakeLists.txt:65 (vtk_module_include)

For completeness my cmake setup steps consists of:

- set CMAKE_BUILD_TYPE:RELEASE
- set VTK_PYTHON_VERSION:3
- run configure
- add VTK_Group_tk:BOOL=ON
- click on advanced
- set VTK_WRAP_PYTHON:BOOL=ON
- run configure
- set VTK_USE_TK:BOOL=ON
- run configure
- manually set TCL_INCLUDE_PATH, TCL_LIBRARY, TCL_TCLSH, TK_INCLUDE_PATH, TK_LIBRARY, TK_WISH
- run configure

It’s very possible that the Tcl/Tk autodetection machinery in VTK is out-of-date and has become broken, since very few people use it.

The error you see in Rendering/Tk/CMakeLists.txt has to do with this code block:

vtk_module_include(VTK::RenderingTk
  PRIVATE
    ${TCL_INCLUDE_PATH}
    ${TK_INCLUDE_PATH}
    ${TK_INTERNAL_PATH})

The error (incorrect number of arguments) suggests that these variables are not set in your CMakeCache.txt (possibly because the Tcl/Tk autodetection isn’t working). You can add them to your CMakeCache.txt manually and then re-run cmake to see if the error goes away. The TK_INTERNAL_PATH might not be necessary, as long as the other two variables are set.

Edit: I just tried using the vtkTkRenderWidget on my own Windows system, and the program exited as soon as the widget was created (no crash or error message, it just quit). So it’s possible that the vtkTkRenderWidget is currently only working on Linux. Hard to be certain, though, since my Windows system is a VM and it doesn’t provide the OpenGL capabilities required by VTK.

Thank you for taking the time and testing the TK bindings and looking in to this. I don’t think I understand Cmake because it seems to me I have the variables set, as my CMakeCache.txt does include:

...

//ADVANCED property for variable: TCL_INCLUDE_PATH
TCL_INCLUDE_PATH-ADVANCED:INTERNAL=1

...

//Path to a file.
TCL_INCLUDE_PATH:PATH=C:\Miniconda3\pkgs\tk-8.6.8-hfa6e2cd_0\Library\include

etc...

But maybe it wouldn’t work anymore anyway.

That’s strange because after I set those variables, VTK configured and built without problems. But I’m not using miniconda, I’m using a Tcl and Tk that I build myself from source a couple years ago.

Hello,I also meet the same question, I want to knonw that you solved it? Thank you !!

hello, I noticed you have answered mang question about VTK binding Tkinter, I meet some questions,can you give me some help,thank you .

If you have some questions, then ask them, and I’ll do my best to answer.

Make sure to say what operating system you use, what version of VTK you are building, what version of Tk, and what you have tried so far.

VTK’s Tk interface is no longer tested and isn’t fully supported, so it isn’t guaranteed to work.

CMake Error at CMake/vtkModule.cmake:1398 (target_include_directories): target_include_directories called with incorrect number of arguments Call Stack (most recent call first): Rendering/Tk/CMakeLists.txt:65 (vtk_module_include)
This is my question, I used vtk9.0.3,tk8.5,windows system,I tried vtk 8.2,generating is successful,but Error compiling using VS.

What are your CMakeCache.txt entries for TCL and TK?

TCL_INCLUDE_PATH, TCL_LIBRARY, TK_INCLUDE_PATH, TK_INTERNAL_PATH, TK_LIBRARY

I just did a Release build with vtk master to confirm it can be done. It should also work with vtk 9.0.3, because I’ve been using the same configuration for a long time. I used python 3.9.3 and Tcl/Tk 8.6.8.

I built Tcl and Tk from source, to match the Tcl/Tk used by Python. For example, in Python39\DLLs:

 Directory of F:\Programs\Python39\DLLs
04/02/2021  11:59 AM         1,705,120 tcl86t.dll
04/02/2021  11:59 AM         1,468,064 tk86t.dll

So I built tcl86t.lib and tk86t.lib. I also built the debug libraries, just in case.

 Directory of F:\Programs\Tcl86\lib
09/22/2018  07:42 AM           184,460 tcl86t.lib
09/22/2018  07:46 AM           185,372 tcl86tg.lib
09/22/2018  08:30 AM           124,930 tk86t.lib
09/22/2018  09:05 AM           125,560 tk86tg.lib

My CMakeCache.txt has the following:

TCL_INCLUDE_PATH:PATH=F:/Programs/Tcl86/include
TCL_LIBRARY:FILEPATH=F:/Programs/Tcl86/lib/tcl86t.lib
TCL_TCLSH:FILEPATH=F:/Programs/Tcl86/bin/tclsh86t.exe
TK_INCLUDE_PATH:PATH=F:/Programs/Tcl86/include
TK_INTERNAL_PATH:PATH=F:/Source/tk8.6.8/win;F:/Source/tk8.6.8/generic
TK_LIBRARY:FILEPATH=F:/Programs/Tcl86/lib/tk86t.lib
TK_WISH:FILEPATH=F:/Programs/Tcl86/bin/wish86t.exe