Location of JDK header files (for JNI code)

T

Torsten Landschoff

Hey there!

I am currently doing my first steps with the Java Native Interface.
Everything is fine so far, but there is one thing I don't like: I have
to adjust the path to the java headers in the Makefile to the system I
am building on.

While this is not a big problem I still don't like this and rather
would like to put something like

JAVA_INCLUDES = javah -includepath

into my Makefile. Many Unix libraries have something like this (based
originally on gtk-config of the GTK+ Widget Toolkit) and I wonder if
something like this is available in (at least) the Sun JDK as well.

TIA for any suggestions/pointers

Torsten
 
G

Gordon Beaton

I have to adjust the path to the java headers in the Makefile to the
system I am building on.

Apparently Blackdown includes a tool j2sdk-config for that purpose,
however that doesn't help much if you're using a different JDK. At any
rate I can't find it in my Blackdown installations, so YMMV:

http://groups.google.com/group/comp.lang.java.programmer/msg/cd0c0a4193eb157e

However you can always use something like this in your (Gnu) Makefile:

ifeq ($(JAVA_HOME),)
JAVA_HOME = $(dir $(shell which javac))..
endif

OSNAME = ($shell uname -s | tr \[A-Z\] \[a-z\])
JAVA_INCLUDES = $(JAVA_HOME)/include $(JAVA_HOME)/include/$(OSNAME)

/gordon
 
R

Roedy Green

I am currently doing my first steps with the Java Native Interface.
Everything is fine so far, but there is one thing I don't like: I have
to adjust the path to the java headers in the Makefile to the system I
am building on.

While this is not a big problem I still don't like this and rather
would like to put something like

JAVA_INCLUDES = javah -includepath

Javah has no trouble finding anything it needs. It is the C/C++
compiler that has trouble finding includes.. The C++ compiler is not
part of Java, neither are its projects to compile the output of Javah
or your hand written C/C++ code.

So unless Java knew how to set up projects for nearly every possible
C/C++ compiler on every possible platform, I don't see how Java could
be responsible for telling the C/C++ compiler about the includes.

I handle it with an embedded comment like this:

you must have
e:\program files\java\jdk1.5.0_04\include\win32
and e:\program files\java\jdk1.5.0_04\include\win32
in tools | options | directories | include

to remind me how to set it up if it gets lost or if I want to set up a
similar project.
 
T

Torsten Landschoff

Hi Gordon,

Gordon said:
Apparently Blackdown includes a tool j2sdk-config for that purpose,
however that doesn't help much if you're using a different JDK. At any
rate I can't find it in my Blackdown installations, so YMMV:

Thanks for the pointer!
However you can always use something like this in your (Gnu) Makefile:

ifeq ($(JAVA_HOME),)
JAVA_HOME = $(dir $(shell which javac))..
endif

OSNAME = ($shell uname -s | tr \[A-Z\] \[a-z\])
JAVA_INCLUDES = $(JAVA_HOME)/include $(JAVA_HOME)/include/$(OSNAME)

That's even more helpful - thanks a bunch! I will use that.

Greetings

Torsten
 
T

Torsten Landschoff

Hi Roedy,

Roedy said:
Javah has no trouble finding anything it needs. It is the C/C++
compiler that has trouble finding includes.. The C++ compiler is not
part of Java, neither are its projects to compile the output of Javah
or your hand written C/C++ code.

So unless Java knew how to set up projects for nearly every possible
C/C++ compiler on every possible platform, I don't see how Java could
be responsible for telling the C/C++ compiler about the includes.

I don't think this is a valid argumentation. The C compiler does not
even know about java. But java was most likely built using a C compiler
(and therefore knows about it) and knows where it has put its include
files. So I think it is reasonable to ask java for the path.

How that can be fed into the C compiler is a completely different
issue.

Greetings

Torsten
 
R

Roedy Green

I don't think this is a valid argumentation. The C compiler does not
even know about java. But java was most likely built using a C compiler
(and therefore knows about it) and knows where it has put its include
files. So I think it is reasonable to ask java for the path.

It appears that under Linux there is some extra problem you don't have
with windows. I assumed your problem was wanting an automatic way to
inform a C/C++ compiler of where the include files were -- how to add
that info to the Borland/MS/Gnu ... C++ project file used to compile
the JNI.
 
G

Gordon Beaton

JAVA_INCLUDES = $(JAVA_HOME)/include $(JAVA_HOME)/include/$(OSNAME)

And of course that last line should have been:

JAVA_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(OSNAME)

/gordon
 
G

Gordon Beaton

It appears that under Linux there is some extra problem you don't
have with windows.

There is no difference between operating systems or compilers in this
regard.
I assumed your problem was wanting an automatic way to inform a
C/C++ compiler of where the include files were -- how to add that
info to the Borland/MS/Gnu ... C++ project file used to compile the
JNI.

The C or C++ compiler needs to know the location of the JNI header
files that are shipped with the JDK. The problem is common to all
platforms, including windows.

The files will be in different locations depending the location of the
JDK, the platform the JDK is intended to run on, and perhaps even the
JDK vendor.

The JDK knows best about its own file layout, and ideally it should be
able to answer questions about it too.

Of course the JDK should not be expected to know how to configure a
Makefile or project file for any number of different compilers, but
that wasn't the issue here. It should be able to *provide* information
about its own file layout in a generic format that can be imported by
other tools.

/gordon
 
R

Raymond DeCampo

Gordon said:
There is no difference between operating systems or compilers in this
regard.




The C or C++ compiler needs to know the location of the JNI header
files that are shipped with the JDK. The problem is common to all
platforms, including windows.

The files will be in different locations depending the location of the
JDK, the platform the JDK is intended to run on, and perhaps even the
JDK vendor.

The JDK knows best about its own file layout, and ideally it should be
able to answer questions about it too.

Of course the JDK should not be expected to know how to configure a
Makefile or project file for any number of different compilers, but
that wasn't the issue here. It should be able to *provide* information
about its own file layout in a generic format that can be imported by
other tools.

I think such a claim would be bolstered by an example of a library that
does do this.

Ray
 
T

Torsten Landschoff

Raymond said:
I think such a claim would be bolstered by an example of a library that
does do this.

He already mentioned kaffe, didn't he? The first library I knew which
does this was the Gimp Toolkit, which provides gtk-config:

torsten@pulsar:~$ gtk-config --cflags
-I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include
torsten@pulsar:~$ gtk-config --libs
-L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl
-lXi -lXext -lX11 -lm

etc.

Greetings

Torsten
 
G

Gordon Beaton

I think such a claim would be bolstered by an example of a library that
does do this.

I can't see that I made any claims in the post you quoted. I expressed
an opinion about information I think a JDK component should be able to
provide.

Regardless, this thread started with a reference to gtk-config, and I
responded with a reference to a Blackdown-specific tool
(j2sdk-config).

/gordon
 
R

Raymond DeCampo

Gordon said:
I can't see that I made any claims in the post you quoted. I expressed
an opinion about information I think a JDK component should be able to
provide.

I was referring to your statement that "[the JDK] should be able to
*provide* information about its own file layout in a generic format that
can be imported by other tools." If you would rather classify that as
an opinion than a claim, fine. This was a genuine inquiry on my part,
not an attempt to disparage you or your ideas or to play language lawyer
or other forms of "gotcha".
Regardless, this thread started with a reference to gtk-config, and I
responded with a reference to a Blackdown-specific tool
(j2sdk-config).

Thanks, I saw those.

Ray
 
G

Gordon Beaton

I think such a claim would be bolstered by an example of a library that
does do this.

I was referring to your statement that "[the JDK] should be able to
*provide* information about its own file layout in a generic format
that can be imported by other tools."

In that case, I'm confused. Isn't that exactly what the examples
already provided do?

/gordon
 
R

Raymond DeCampo

Gordon said:
I think such a claim would be bolstered by an example of a library that
does do this.


I was referring to your statement that "[the JDK] should be able to
*provide* information about its own file layout in a generic format
that can be imported by other tools."


In that case, I'm confused. Isn't that exactly what the examples
already provided do?

You are reading too much into this. :)

In the second quote above, I was clarifying which statement I
interpreted as a "claim", since you stated that you were unaware of any
claims made in your post.

I wasn't implying that the examples given elsewhere were invalid.

Ray
 

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

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top