Building VTK for Mac M1+ARM : Undefined symbols: _JAWT_GetAWT

Hi,

I am trying to build VTK 9.1.0-rc2 on a Mac M1 with an ARM64. I am blocked at

[ 38%] Linking CXX shared library ../../lib/java/vtk-Darwin-arm64/libvtkRenderingCoreJava.jnilib
Undefined symbols for architecture arm64:
  "_JAWT_GetAWT", referenced from:
      _Java_vtk_vtkPanel_RenderCreate in vtkRenderWindowJava.mm.o
      _Java_vtk_rendering_awt_vtkInternalAwtComponent_RenderCreate in vtkRenderWindowJava.mm.o
      _Java_vtk_vtkPanel_Lock in vtkRenderWindowJava.mm.o
      _Java_vtk_vtkPanel_UnLock in vtkRenderWindowJava.mm.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/java/vtk-Darwin-arm64/libvtkRenderingCoreJava.jnilib] Error 1
make[1]: *** [Wrapping/Java/CMakeFiles/vtkRenderingCoreJava.dir/all] Error 2
make: *** [all] Error 2

There are old post saying that the AWT include path should be replaced by -framework JavaVM, Apple forums suggest to rather use -framework JavaNativeFoundation since a year ago, but none of this work :

[ 40%] Linking CXX shared library ../../lib/java/vtk-Darwin-arm64/libvtkRenderingCoreJava.jnilib
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/System/Library/Frameworks//JavaNativeFoundation.framework/JavaNativeFoundation.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/System/Library/Frameworks//JavaNativeFoundation.framework/JavaNativeFoundation.tbd
Undefined symbols for architecture arm64:
  "_JAWT_GetAWT", referenced from:
      _Java_vtk_vtkPanel_RenderCreate in vtkRenderWindowJava.mm.o
      _Java_vtk_rendering_awt_vtkInternalAwtComponent_RenderCreate in vtkRenderWindowJava.mm.o
      _Java_vtk_vtkPanel_Lock in vtkRenderWindowJava.mm.o
      _Java_vtk_vtkPanel_UnLock in vtkRenderWindowJava.mm.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/java/vtk-Darwin-arm64/libvtkRenderingCoreJava.jnilib] Error 1
make[1]: *** [Wrapping/Java/CMakeFiles/vtkRenderingCoreJava.dir/all] Error 2
make: *** [all] Error 2

My CMake configuration is as follow. The chosen JVM is a Zulu 11 for ARM processors.

LD is supposed to support my processor

ld -v
@(#)PROGRAM:ld PROJECT:ld64-711
BUILD 14:59:28 Aug 21 2021
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 13.0.0, (clang-1300.0.29.3) (static support for 27, runtime is 27)
TAPI support using: Apple TAPI version 13.0.0 (tapi-1300.0.6.5)

Thanks in advance for your help!

Cc: @dgobbi @toddy

It looks like the JavaNativeFoundation being used is not built for arm64.

That is also my assumption.

However I think I should be able to build by referencing Azul JDK 11 as I did. To clarify, the first link error message refer to the CMake configuration screenshot where I do not use the -framework flag.

Why don’t you just try a JNF built for arm64. I believe xcode provides one.

I could try to setup this. But what happens with this -framework flag? Isn’t it possible to link against any JDK by configuring via CMake as I did? Why would it work better with JNF?

You could try command line
arch -arm64 cmake

This was due to erroneous Java path definition pointing to folders instead of dylib files.

Here is the correct configuration

There really should be a cmake warning about the missing lib file names.

Feel free to submit patches to sanity check the Java variables in use. Erroring is fine too if we know they’re not OK.

There were warning about not readable libraries but stupidly missed them because of minimizing the output panel from CMake GUI.

Anyway, build is OK but will halt a bit further while creating the jar, so I followed your suggestions here and manually did

cd Wrapping/Java/CMakeFiles/vtkjava.dir/
jar --create -f ../../../../lib/java/vtk-9.1.0.jar vtk

And then I can run Java wrapper \o/ thanks for your help and your posts about Java :slight_smile:

Just out of interest which compiler are you using to build for ARM architecture? Clang?

Yes I think.

If you are also willing to run VTK for Java on ARM, then you might be interested by this JOGL release adding support for ARM : GitHub - jzy3d/jogl-maven-deployer: Scripts to make a maven distribution out of JOGL 2.4. It is not an official one, I just hacked gluegen and jogl and left other projects for latter.