Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

Location of JDK header files (for JNI code)

Thread view: 
Torsten Landschoff - 10 Sep 2005 13:13 GMT
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
Gordon Beaton - 10 Sep 2005 16:05 GMT
> 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

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

Torsten Landschoff - 10 Sep 2005 23:15 GMT
Hi Gordon,

Gordon Beaton schrieb:
> > 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:

Thanks for the pointer!

> However you can always use something like this in your (Gnu) Makefile:
>
[quoted text clipped - 4 lines]
>   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
Gordon Beaton - 12 Sep 2005 08:21 GMT
>   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

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 - 10 Sep 2005 21:56 GMT
>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
[quoted text clipped - 5 lines]
>
>  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.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Torsten Landschoff - 10 Sep 2005 23:19 GMT
Hi Roedy,

Roedy Green schrieb:
> Javah has no trouble finding anything it needs.  It is the C/C++
> compiler that has trouble finding includes.. The C++ compiler  is not
[quoted text clipped - 4 lines]
> 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
Roedy Green - 11 Sep 2005 00:12 GMT
>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.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Gordon Beaton - 12 Sep 2005 15:31 GMT
> 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

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

Raymond DeCampo - 13 Sep 2005 18:50 GMT
>>It appears that under Linux there is some extra problem you don't
>>have with windows.
[quoted text clipped - 23 lines]
> 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

Signature

XML is the programmer's duct tape.

Torsten Landschoff - 13 Sep 2005 19:06 GMT
Raymond DeCampo schrieb:

> 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
Gordon Beaton - 13 Sep 2005 19:30 GMT
> 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

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

Raymond DeCampo - 13 Sep 2005 20:48 GMT
>>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.

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

Signature

XML is the programmer's duct tape.

Gordon Beaton - 14 Sep 2005 07:51 GMT
>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

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

Raymond DeCampo - 14 Sep 2005 13:42 GMT
>>I think such a claim would be bolstered by an example of a library that
>>does do this.
[quoted text clipped - 5 lines]
> 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

Signature

XML is the programmer's duct tape.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.