Reputation: 7341
I'm getting a compilation error for the following header file:
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
jint x1;
jint y1;
jint x2;
jint y2;
} Bounds;
...
#ifdef __cplusplus
};
#endif
There are other JNI references, such as to jobject
, JNIEnv
, JavaVM
, etc.
It's not complaining that the <jni.h> header is missing (it was, but that was easily fixed by adding the include path). I've checked the header file and the types are defined in that header (and <jni_md.h> too).
This isn't making any sense to me. Any ideas?
EDIT: I forgot to include the following error text.
g++ -O2 -fPIC -fpermissive -I. -I.. -I/usr/include -I/usr/local/include/libavcodec -I/usr/local/include/libavdevice -I/usr/local/include/libavformat -I/usr/local/include/libswscale -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -DUNIX -shared -c -o Plugin.o Plugin.cpp
clang: warning: argument unused during compilation: '-shared'
In file included from Plugin.cpp:19:
In file included from Plugin.h:16:
Data.h:24:5: error: unknown type name 'jint'
jint x1;
^
Data.h:25:5: error: unknown type name 'jint'
jint y1;
^
Data.h:26:5: error: unknown type name 'jint'
jint x2;
^
Data.h:27:5: error: unknown type name 'jint'
jint y2;
^
Upvotes: 1
Views: 2500
Reputation: 13385
This is strange, indeed.
You can take a look at very similar code, that compiles just fine here:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo025
Just one remark in your case. While you compile your code, don't use
-shared
You should use it while building shared library:
# compile the code
g++ -O2 -fPIC -fpermissive -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -DUNIX -c -o c/recipeNo025_HelloWorld.o c/recipeNo025_HelloWorld.cpp
# make shared lib out of it
g++ -g -shared c/recipeNo025_HelloWorld.o -o lib/libHelloWorld.$(EXT)
Upvotes: 0
Reputation: 3360
The C code does not have any obvious error and it is compilable if the development environment is correctly set up. So the suspected area is the development environment and that is probably missing or corrupted JNI header files.
The C compiler provides the option -E
which and compiler runs preprocessor only when the option is applied. The output might be analyzed contains locations where the header files was found expanded ifdefs and so on.
The preprocessor output shows the wrong jni.h
file was included. The solution is to properly setup the project include paths the include the correct jni.h
.
Upvotes: 1