Cannot build vtk with Java Wrapping

I try to build vtk with Java Wrapping to simply read and write vtk-Files. This is my setup:

  • Ubuntu 22.10
  • cmake version 3.24.2
  • GNU Make 4.3
  • openjdk 17.0.6 2023-01-17
  • vtk branch master

I can build (run make after configuring with cmake unchanged settings) without Java Wrapping successfully.
With Java Wrapping the build fails. After setting all cmake options of Type VTK_GROUP_ENABLE_… to DONT_WANT I get the following error message:

[ 37%] Building CXX object Wrapping/Java/CMakeFiles/vtkCommonDataModelJava.dir/CMakeFiles/vtkCommonDataModelJava/vtkCellMetadataJava.cxx.o
/home/st/git/vtk/out/build/Wrapping/Java/CMakeFiles/vtkCommonDataModelJava/vtkCellMetadataJava.cxx: In function ‘jboolean Java_vtk_vtkCellMetadata_RegisterType_14(JNIEnv*, jobject)’:
/home/st/git/vtk/out/build/Wrapping/Java/CMakeFiles/vtkCommonDataModelJava/vtkCellMetadataJava.cxx:80:28: error: no matching function for call to ‘vtkCellMetadata::RegisterType()’
   80 |   temp20 = op->RegisterType();
      |            ~~~~~~~~~~~~~~~~^~
In file included from /home/st/git/vtk/out/build/Wrapping/Java/CMakeFiles/vtkCommonDataModelJava/vtkCellMetadataJava.cxx:6:
/home/st/git/vtk/Common/DataModel/vtkCellMetadata.h:69:15: note: candidate: ‘template<class Subclass> static bool vtkCellMetadata::RegisterType()’
   69 |   static bool RegisterType()
      |               ^~~~~~~~~~~~
/home/st/git/vtk/Common/DataModel/vtkCellMetadata.h:69:15: note:   template argument deduction/substitution failed:
/home/st/git/vtk/out/build/Wrapping/Java/CMakeFiles/vtkCommonDataModelJava/vtkCellMetadataJava.cxx:80:28: note:   couldn’t deduce template parameter ‘Subclass’
   80 |   temp20 = op->RegisterType();
      |            ~~~~~~~~~~~~~~~~^~
make[2]: *** [Wrapping/Java/CMakeFiles/vtkCommonDataModelJava.dir/build.make:2813: Wrapping/Java/CMakeFiles/vtkCommonDataModelJava.dir/CMakeFiles/vtkCommonDataModelJava/vtkCellMetadataJava.cxx.o] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:21825: Wrapping/Java/CMakeFiles/vtkCommonDataModelJava.dir/all] Fehler 2
make: *** [/home/st/git/vtk/out/build/Makefile:136: all] Fehler 2
make[2]: Verzeichnis „/home/st/git/vtk/out/build“ wird verlassen
make[1]: Verzeichnis „/home/st/git/vtk/out/build“ wird verlassen
make: Verzeichnis „/home/st/git/vtk/out/build“ wird verlassen

I fixed this error by simply removing the static method RegisterType() from vtkCellMetadata.h.

With this dirty fix the build succeeds and I can create an vtkUnstructuredGrid and fill it with model data, but I do not have vtkXMLUnstructuredGridReader and vtkXMLUnstructuredGridWriter available.

As soon as I activate VTK_ENABLE_GROUP_… options I get the following error message:

[ 53%] Linking Java static library ../../lib/java/vtk.jar
[ 74%] Built target vtkjava
make: *** [Makefile:136: all] Fehler 2

The build seems to be incomplete: can read and write vtu-files, but misses many libraries.

I am not a C programmer and try to make good guesses.
Is the Java Wrapping feature still supported, am I missing something?
Any help is very welcome.


Thanks for reporting these issues. Templated methods are meant to be automatically excluded from Java wrapping, but I think I know why those ones slipped through. I’ll put together a patch for the master branch.

You might have more luck building the release branch, since master isn’t regular tested with Java wrapping (the vtkCellMetadata class isn’t in the release branch, it’s a recently-added class).

Not sure what’s going on with VTK_ENABLE_GROUP_X, but I can look into that too. My guess is that it’s actually a red herring, and the real problem is that the dependency rules for building the Java wrappers are a bit messed up.

1 Like

Thank you so much for your quick help.

Using the branch origin/release did the trick. Build and my example are working now without problems.