Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value for annotation attribute Array.value must be a constant #354

Closed
igler opened this issue Jan 8, 2013 · 9 comments
Closed

The value for annotation attribute Array.value must be a constant #354

igler opened this issue Jan 8, 2013 · 9 comments

Comments

@igler
Copy link

igler commented Jan 8, 2013

When generating Java code through 'mvn com.nativelibs4java:maven-jnaerator-plugin:generate' the generated Java-code looks like this:

@array({(int)de.test.MyLibrary.tipmon_sizes.TIP_GDA_DATA_LENGTH.value()})

Java compiler complains with the error:

"The value for annotation attribute Array.value must be a constant"

How can I solve the issue? The Java version I use is jdk1.7.0_09

@ochafik
Copy link
Member

ochafik commented Jan 8, 2013

Hi @igler ,

Thanks for your report!
Could you please reproduce a self-sufficient C source snippet which leads to such generated code?

Using the freshly-released version 0.11 of JNAerator on the following snippet, things appear to work:

const int LEN1 = 10;
#define LEN2 20
struct S {
    int a[LEN1];
    int b[LEN2];
};

Cheers

@igler
Copy link
Author

igler commented Jan 8, 2013

Hi,

I use the following maven plugins:

com.nativelibs4java bridj 0.6.1 com.nativelibs4java maven-jnaerator-plugin 0.10 maven-plugin

Who is uploading recent version of 'maven-jnaerator-plugin' to maven repository?

The C-code that causes the warning/error looks like:

...
enum tipmon_sizes
{
...
TIP_ITEMID_LENGTH = 31,
...
};
...
struct
{
...
wschar_t progid[TIP_ITEMID_LENGTH];
...
} sys;
...

The generated Java code is:
...
/// C type : wschar_t[TIP_ITEMID_LENGTH]
@array({(int)de.test.MLibrary.tipmon_sizes.TIP_ITEMID_LENGTH.value()})
@field(4)
public Pointer progid() {
return this.io.getPointerField(this, 4);
}
...

@ochafik
Copy link
Member

ochafik commented Jan 8, 2013

Hi @igler ,

Thanks for these details!
The way enum items are handled right now doesn't play well with constant expressions in Java, indeed...
Will try and address this asap :-)

Oh, and JNAerator 0.11 & BridJ 0.6.2 have just been synced to Maven Central (they still exhibit the same issue but bring along tons of other fixes, please give them a try :-)).

Cheers

@igler
Copy link
Author

igler commented Jan 8, 2013

Thanx for the info. Using them henceforth.

... but the annotation-error persists. A soon fix would be nice :-)

@ochafik
Copy link
Member

ochafik commented Jan 8, 2013

As a temporary workaround, you can try defining that item as a constant with -DTIP_ITEMID_LENGTH=31

@igler
Copy link
Author

igler commented Jan 29, 2013

Tried 'mvn -DTIP_ITEMID_LENGTH=31 com.nativelibs4java:maven-jnaerator-plugin:generate' but the generated code is not different.

@ochafik
Copy link
Member

ochafik commented Jan 29, 2013

Hi @igler,

This argument needs to be passed to JNAerator using its configuration file (Maven's -D argument defines a system property, which is not what we want here).
You can simply add it to your src/main/jnaerator/config.jnaerator file :-)

Cheers

@igler
Copy link
Author

igler commented Jan 30, 2013

Well, added it to config.jnaerator but then I get additional errors. The callback functions I added to my C-header are not generated any more.

The config:
-DTIP_ITEMID_LENGTH=31
-f
-library MYLIB
-mode Directory
-package myPackage.MYLIB
/path/to/header/tipmon.h

@ochafik
Copy link
Member

ochafik commented Jun 9, 2013

Hi @igler ,

Sorry for the long delay, this should be fixed in the latest 0.12-SNAPSHOT.
Cheers

@ochafik ochafik closed this as completed Jun 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants