Problems getting started with gluten

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems getting started with gluten

Jennifer Milburn
I'm just getting started with gluegen and I'm running into several problems. (Probably fairly dumb ones).  I've downloaded the current version using git and tried to build it a couple of different ways.
(1) Using the Netbeans project I can build. However, the source code appears to have a whole set of unsatisfied dependencies mainly related to import of android (e.g. import android.*). I'd like to include the android jar in the class path so these error flags go away but I can't find a simple android.jar.  It appears that you need to install a complete android SDK and I'm only interested in including the classes that are needed to satisfy gluegen.
(2) I'm really not interested in building gluegen but simply using it to generate the JNI interface required to interface with a couple of different scientific cameras using their header files.  I've tried simply downloading the .7z file for the operating system (MacOS) and running gluengen from the jar file (i.e. java -jar gluegen -I /mypath/to/example) using one of the examples in the doc folder but I get the same error:

Exception in thread "main" java.lang.NoClassDefFoundError: antlr/RecognitionException
Caused by: java.lang.ClassNotFoundException: antlr.RecognitionException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I have the ant-antlr.jar file in the same folder as the gluegen.jar file and I can't figure out what I'm doing wrong.
Anyone have any clue as to what's wrong?

Sincerely,
Jennifer Milburn
jwm@astro.caltech.edu
Reply | Threaded
Open this post in threaded view
|

Re: Problems getting started with gluten

Wade Walker
Administrator
Hi Jennifer,

The antlr/RecognitionException dependency is on antlr.jar, which is in gluegen/make/lib. If you add that to your classpath, gluegen should be able to run correctly.

To build gluegen (which it doesn't seem like you want to do, but just in case), just follow the instructions at http://jogamp.org/wiki/index.php/Building_JOGL_on_the_command_line, but ignore the parts about the jogl project. You don't need the Android SDK to do this build -- the whole thing should complete on the command line with no external dependencies (other than Java, Ant, and Git).

Reply | Threaded
Open this post in threaded view
|

Re: Problems getting started with gluten

Jennifer Milburn
Thanks Wade,
   I had ant-antlr.jar on the class path (i.e. in the same directory) but I guess it was looking for antlr.jar. Your suggestion helped and I was able to generate the source code for one of the examples!  It appears that I can generate the JNI code for simple examples now.  I just tried generating the JNI code for the actual header file I need to work with and got a variety of errors.  However, it's clear that the gluegen is at least attempting to generate the JNI code.
     I'm just trying to test the generation process on MacOS so I don't really expect this to work completely.  I'm going to generate different JNI classes for Windows and Linux using their respective header files (i.e. slightly different header for the two operating systems).  However, I am getting a large number of errors mostly related to ANTLR running into an unexpected token
"extern" in the header.  

ANTLR Parsing Error: line 122:4919: unexpected token: extern token name:"extern"
line 122:4919: unexpected token: extern
        at com.jogamp.gluegen.cgram.GnuCParser.externalDef(GnuCParser.java:522)
        at com.jogamp.gluegen.cgram.GnuCParser.externalList(GnuCParser.java:258)
        at com.jogamp.gluegen.cgram.GnuCParser.translationUnit(GnuCParser.java:219)
        at com.jogamp.gluegen.GlueGen.run(GlueGen.java:131)
        at com.jogamp.gluegen.GlueGen.main(GlueGen.java:363)
(note there are about 30 of these errors)

I'm also getting the following error that is a little more serious.  Is this related to a limitation of JNI for this kind of method (i.e. a callback reference?)

Exception in thread "main" java.lang.RuntimeException: Exception occurred while generating glue code.
        at com.jogamp.gluegen.GlueGen.run(GlueGen.java:304)
        at com.jogamp.gluegen.GlueGen.main(GlueGen.java:363)
Caused by: java.lang.RuntimeException: Error while generating bindings for "int AT_RegisterFeatureCallback(AT_H Hndl, const AT_WC *  Feature, int (*EvCallback)(AT_H Hndl, const AT_WC *  Feature, void *  Context), void *  Context);"
        at com.jogamp.gluegen.JavaEmitter.generateMethodBindingEmitters(JavaEmitter.java:726)
        at com.jogamp.gluegen.JavaEmitter.emitFunctions(JavaEmitter.java:419)
        at com.jogamp.gluegen.GlueGen.run(GlueGen.java:297)
        ... 1 more
Caused by: java.lang.RuntimeException: Don't know how to convert pointer/array type "FeatureCallback"
        at com.jogamp.gluegen.JavaEmitter.typeToJavaType(JavaEmitter.java:1292)
        at com.jogamp.gluegen.JavaEmitter.bindFunction(JavaEmitter.java:1717)
        at com.jogamp.gluegen.JavaEmitter.generateMethodBindingEmitters(JavaEmitter.java:651)
        ... 3 more

Any insight would be appreciated :)  I don't have any control over the header or the C interface.  I'm simply trying to create a java interface to the cameras drivers for Linux and Windows and the drivers are provided by the manufacturer.
Sincerely,
Jennifer Milburn
Reply | Threaded
Open this post in threaded view
|

Re: Problems getting started with gluten

Sven Gothel
Administrator
On Sunday, January 22, 2012 11:29:35 PM Jennifer Milburn [via jogamp] wrote:

>
> Thanks Wade,
>    I had ant-antlr.jar on the class path (i.e. in the same directory) but I
> guess it was looking for antlr.jar. Your suggestion helped and I was able to
> generate the source code for one of the examples!  It appears that I can
> generate the JNI code for simple examples now.  I just tried generating the
> JNI code for the actual header file I need to work with and got a variety of
> errors.  However, it's clear that the gluegen is at least attempting to
> generate the JNI code.
>      I'm just trying to test the generation process on MacOS so I don't
> really expect this to work completely.  I'm going to generate different JNI
> classes for Windows and Linux using their respective header files (i.e.
> slightly different header for the two operating systems).  However, I am
> getting a large number of errors mostly related to ANTLR running into an
> unexpected token
> "extern" in the header.  
>
> ANTLR Parsing Error: line 122:4919: unexpected token: extern token
> name:"extern"
> line 122:4919: unexpected token: extern
> at com.jogamp.gluegen.cgram.GnuCParser.externalDef(GnuCParser.java:522)
> at com.jogamp.gluegen.cgram.GnuCParser.externalList(GnuCParser.java:258)
> at com.jogamp.gluegen.cgram.GnuCParser.translationUnit(GnuCParser.java:219)
> at com.jogamp.gluegen.GlueGen.run(GlueGen.java:131)
> at com.jogamp.gluegen.GlueGen.main(GlueGen.java:363)
> (note there are about 30 of these errors)
>
> I'm also getting the following error that is a little more serious.  Is this
> related to a limitation of JNI for this kind of method (i.e. a callback
> reference?)
>
> Exception in thread "main" java.lang.RuntimeException: Exception occurred
> while generating glue code.
> at com.jogamp.gluegen.GlueGen.run(GlueGen.java:304)
> at com.jogamp.gluegen.GlueGen.main(GlueGen.java:363)
> Caused by: java.lang.RuntimeException: Error while generating bindings for
> "int AT_RegisterFeatureCallback(AT_H Hndl, const AT_WC *  Feature, int
> (*EvCallback)(AT_H Hndl, const AT_WC *  Feature, void *  Context), void *
> Context);"
> at
> com.jogamp.gluegen.JavaEmitter.generateMethodBindingEmitters(JavaEmitter.java:726)
> at com.jogamp.gluegen.JavaEmitter.emitFunctions(JavaEmitter.java:419)
> at com.jogamp.gluegen.GlueGen.run(GlueGen.java:297)
> ... 1 more
> Caused by: java.lang.RuntimeException: Don't know how to convert
> pointer/array type "FeatureCallback"
> at com.jogamp.gluegen.JavaEmitter.typeToJavaType(JavaEmitter.java:1292)
> at com.jogamp.gluegen.JavaEmitter.bindFunction(JavaEmitter.java:1717)
> at
> com.jogamp.gluegen.JavaEmitter.generateMethodBindingEmitters(JavaEmitter.java:651)
> ... 3 more
>
> Any insight would be appreciated :)  I don't have any control over the
> header or the C interface.  I'm simply trying to create a java interface to
> the cameras drivers for Linux and Windows and the drivers are provided by
> the manufacturer.

Without seeing your c-header input files
I am not able to determine the source of the error,
ie whether they come from the input or GlueGen itself.

GlueGen itself includes test code and headers which are being parsed
and code generated for:
  src/junit/com/jogamp/gluegen/test/junit/generation/test1.h

The following class tests the generated signatures _and_ the proper data handling:
  src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java

Even though they are pretty simple, they demonstrate how it should work.

In JOGL for example, you can see more elaborated use of GlueGen
including dealing with API specific macros like GL_API .. etc.

Reading your error messages it is at least clear that not all macros are resolved,
eg. AT_H, AT_WC, Feature .. etc .. - but they all need to be resolved to have GlueGen
parse valid C headers.

One way is to include specific headers for the GlueGen processing
where you resolve them in a special way, or use the proper headers if this is possible.
You also could define types as opaque etc .. in the config files.

~Sven

> Sincerely,
> Jennifer Milburn
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems getting started with gluten

Wade Walker
Administrator
In reply to this post by Wade Walker
The "unexpected token" error is what ANTLR says when the file it's parsing doesn't match the grammar it's using. This could mean that the header file you're trying to create a JNI interface for may contain some feature of C that the GlueGen parser doesn't properly support.

My suggestion would be to make a copy of your input header file, then edit it to remove the "extern" keywords which seem to be causing the errors, and run GlueGen again. If the errors go away, examine the resulting JNI interface to see if it's correct. If so, we may need to extend the GlueGen grammar a bit.