gcc with JNI
First question, is I have my JNI code split into separate header and c files reflecting the Java classes I'm using to call a 3rd party dll. Originally I tried to compile all of them on one commandline. This gave me a lot of "redefinition" errors or warnings. So now I am compiling each file separate and it works fine. However, it means in the future I will have a command line for each. Is that an inherent limit in gcc or is there a way around it.
Second, I would like to make the code as clean as possible, so I'm using the flags -mno-cygwin -Wall -O. I keep getting warnings about casting and imcompatible types. Keep chasing them around with various ways of handling pointers, etc and only seem to create new problems. Recommendations on a high level C book.
Third, tried to use the flags -ansi and -pedantic to keep the C strict but got warnings and error going back into the jni.h and my 3rd party dll header file. Does this mean that JNI is not strict C compliant?
Thanks,
Jim
# 1
> First question, is I have my JNI code split into
> separate header and c files reflecting the Java
> classes I'm using to call a 3rd party dll. Originally
> I tried to compile all of them on one commandline.
> This gave me a lot of "redefinition" errors or
> warnings. So now I am compiling each file separate
> and it works fine. However, it means in the future I
> will have a command line for each. Is that an
> inherent limit in gcc or is there a way around it.
I use Ant:
http://ant.apache.org/
along with the cc Task:
http://ant-contrib.sourceforge.net/cc.html
>
> Second, I would like to make the code as clean as
> possible, so I'm using the flags -mno-cygwin -Wall
> -O. I keep getting warnings about casting and
> imcompatible types. Keep chasing them around with
> various ways of handling pointers, etc and only seem
> to create new problems. Recommendations on a high
> level C book.
Have you searched Google et. al. for the warning message text?
>
> Third, tried to use the flags -ansi and -pedantic to
> keep the C strict but got warnings and error going
> back into the jni.h and my 3rd party dll header file.
> Does this mean that JNI is not strict C compliant?
Not necessarily.
For example, a simple HelloWorld app compiled with '-ansi -pedantic' flags generates the following warning:
jni_md.h:19: warning: ISO C90 does not support 憀ong long?
A Google search for:
"ISO C90 does not support 憀ong long?br>
yields this link:
http://grass.itc.it/pipermail/grass5/2006-February/021029.html
which suggests adding the -std=c99 flag.
Doing so results in a clean compile.
# 3
I'm guessing that your "redefinition" problems are because your .h files are not protected.
In each file you should surround everything - that is place before and after your specific code - preprocessor directives to prevent reuse.
As an example, image there is a .h call native_stuff.h
A typical C programmer will place the following in the file:
#ifndef _NATVE_STUFF_H
#define _NATIVE_STUFF_H
all of his definitions go here
#endif // _NATIVE_STUFF_H
This tells the proprocesor to skip these definitions if they have already been seen.