> My g++ compiler doesn't know where my jni.h file is. I don't know
> how to explicit tell to g++ that jni.h is in the include folder of
> java.
The standard compiler flag for extending the header search path is -I.
You need to add two directories, like this:
-I $JAVA_HOME/include -I $JAVA_HOME/include/linux
(assuming an appropriately set JAVA_HOME)
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
> Hi,
>
[quoted text clipped - 7 lines]
>
> What should I do ? (I am working on Linux)
man gcc helps ;)
If you ask again in comp.lang.c, you will probably be flamed to death,
then told about the magic -I switches to gcc (and most other C compilers),
which add directories to the search path.
Since i am in a good mood right now: -I<path/to/your/java/install>/include
and -I<path/to/your/java/install>/include/linux

Signature
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"
Marcelo - 14 Nov 2005 08:37 GMT
thanks,
I would like to avoid the command -I
How can I do it? Should I add my /usr/local/.../java.../include in the
path variable, or should I create a new variable?
thanks a lot
Marcelo
Gordon Beaton - 14 Nov 2005 07:58 GMT
> I would like to avoid the command -I
> How can I do it? Should I add my /usr/local/.../java.../include in the
> path variable, or should I create a new variable?
Your PATH has nothing to do with this.
What are your reasons for wanting to avoid using -I, when it is
clearly the correct solution?
Write a Makefile, and add the -I options to your CFLAGS variable.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Marcelo - 14 Nov 2005 09:15 GMT
thanks for the make file,
now i am getting another problem , a little bit strange
~/docs/jni/jniexamples/chap2/HelloWorld$
gcc -I/usr/local/share/jdk1.5.0_05/include
-I/usr/local/share/jdk1.5.0_05/include/linux HelloWorld.c
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status
the program is the HelloWorld application the Sun Tutorials.
thanks a lot,
Marcelo
Gordon Beaton - 14 Nov 2005 08:52 GMT
> thanks for the make file,
>
[quoted text clipped - 9 lines]
>
> the program is the HelloWorld application the Sun Tutorials.
Because you didn't tell the compiler you wanted a shared library it
tried to compile a program, which needs a main().
Compile your code like this:
gcc -fPIC -D_REENTRANT
-I $JAVA_HOME/include
-I $JAVA_HOME/include/linux
-c HelloWorld.c
Then link the shared library like this:
gcc -shared HelloWorld.o -o libhello.so
Or compile and link with a single command:
gcc -fPIC -shared -D_REENTRANT
-I $JAVA_HOME/include
-I $JAVA_HOME/include/linux
HelloWorld.c
-o libhello.so
(note that each command should be a single line)
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Roedy Green - 14 Nov 2005 10:37 GMT
> gcc -shared HelloWorld.o -o libhello.so
and that is deliberate, you use the same gcc for linking as compiling?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Gordon Beaton - 14 Nov 2005 10:21 GMT
>> gcc -shared HelloWorld.o -o libhello.so
>
> and that is deliberate, you use the same gcc for linking as compiling?
Yes.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Marcelo - 14 Nov 2005 10:23 GMT
> thanks for the make file,
>
[quoted text clipped - 13 lines]
>
> Marcelo
got the solution
I should use the -shared option in the compilator
thanks
Marcelo