jni.h problem

G

Gordon Beaton

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
 
G

Gordon Beaton

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
 
M

Marcelo

Hi,

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.

I get the error

HelloWorld.c:1:17: error: jni.h: No such file or directory

What should I do ? (I am working on Linux)

thanks

MArcelo
 
S

Stefan Schulz

Hi,

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.

I get the error

HelloWorld.c:1:17: error: jni.h: No such file or directory

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
 
M

Marcelo

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
 
G

Gordon Beaton

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.

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
 
M

Marcelo

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
 
M

Marcelo

Marcelo said:
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
got the solution

I should use the -shared option in the compilator
thanks

Marcelo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,097
Latest member
RayE496148
Top