You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generating wrappers of macOS SDK Foundation framework #5
@manuelbl I have been advised to explore your work to go further with JExtract/Panama that I use to generate Java bindings to OpenGL.
You seam to be experienced at generating bindings to macOS SDK frameworks so I'd like to ask how you deal with surprising cases such as in Foundation/NSObjCRuntime.h at line 492. The @Class keyword does not seam to be regular C language to me.
The code you're showing is clearly Objective-C code. This won't work. And the problem likely is that it was picked for processing in the first place. Unfortunately, your question doesn't show what command caused the problem.
Don't include the framework header file directly. Instead create a helper file using the #include statement with angular brackets:
opengl_helper.h
#include <GLUT/glut.h>
Clang (jextract) will correctly resolve such include statements if the -F option points to the macOS SDK. In the current jextract version, this unfortunately can only be specified with a separate compile_flags.txt file:
Ah, so you were trying to use the AppKit framework.
It seems that the majority of frameworks are Objective-C frameworks. They cannot be used from C and thus not from Panama either.
I don't have a list of C vs Objective-C frameworks. But if grep finds matches for #import in the Versions/Current/Headers subdirectory, it seems to be an Objective-C framework.
Activity
manuelbl commentedon Jan 2, 2023
The code you're showing is clearly Objective-C code. This won't work. And the problem likely is that it was picked for processing in the first place. Unfortunately, your question doesn't show what command caused the problem.
My approach for dealing with macOS frameworks can be seen at https://github.com/manuelbl/JavaDoesUSB/tree/main/java-does-usb/jextract/macos. Translated to the GLUT framework, it looks like this (for JDK 19 / jextract 19):
Don't include the framework header file directly. Instead create a helper file using the #include statement with angular brackets:
opengl_helper.h
Clang (jextract) will correctly resolve such include statements if the
-Foption points to the macOS SDK. In the current jextract version, this unfortunately can only be specified with a separatecompile_flags.txtfile:compile_flags.txt
Then call jextract like so:
This will generate 266 files. The file
RuntimeHelper.javaneeds to be modified. The following lines need to be deleted:and then replaced with:
jzy3d commentedon Jan 2, 2023
Thank you a lot for taking time to answer with details.
I have been able to generate the binding for GLUT that I made available here if you are interested.
I had a slightly different approach to deal with other macOS SDK.
I first define links toward all folder that I want to include :
So that I can later refer to a single include folder that Clang properly handle.
Then if I want AppKit I do this
I tried to generate bindings to AppKit.h with the hope to have Java bindings allowing to do something similar to OSXmisc.m in JOGL - which starts by including AppKit.
However the function I want to reproduce with Panama has non C/C++ code inside, so this might not work from Panama :(
Maybe I'll have to keep this in pure JNI and mainly bind to GL/GLU/GLUT/CGL with Panama.
Thanks for having cleanly documented your project, that was really instructive for me!
manuelbl commentedon Jan 2, 2023
Ah, so you were trying to use the AppKit framework.
It seems that the majority of frameworks are Objective-C frameworks. They cannot be used from C and thus not from Panama either.
I don't have a list of C vs Objective-C frameworks. But if grep finds matches for
#importin theVersions/Current/Headerssubdirectory, it seems to be an Objective-C framework.jzy3d commentedon Jan 21, 2023
Thank you a lot, your answer help a lot on bumping my project to JDK19 :)
jzy3d commentedon Jan 21, 2023
For your information : I also add to delete
System.loadLibrary("OpenGL.framework");