[vtkusers] Help with linking C++ native code for Java JNI

Leue, William M (Research) leue at crd.ge.com
Fri Jun 6 10:14:12 EDT 2003


Greg,
 
>From the Sun book on JNI by Sheng Liang, here is a rough outline of the
process:
 
1. Create a Java class that declares the native method. (e.g. myClass.java)
2. Use the Java compiler, javac, to compile the Java class, resulting in the
file myClass.class
3. Use the javah -jni utility to create a C header file myClass.h
4. Write the C implementation of the native method, e.g. myJNI.c
5. Compile the C implementation into a native dynamic library, e.g.,
myJNI.dll or myJNI.so
6. Run the myClass Java program using 'java myClass.class'. The Java class
loader will dynamically load your Java class and the native method library.
 
If you are using, say, MS Visual C++, you can use the new project wizard to
tell it you are building a DLL instead of an application. It will put all
the appropriate linker flags in for you to build a dll.
 
Starting with a 'hello world' program that does not try to pass any data
between the C and Java worlds is a good first step.
 
-Bill Leue

-----Original Message-----
From: Greg Scott [mailto:g.scott at oneteldsl.net]
Sent: Friday, June 06, 2003 10:03 AM
To: vtkusers at public.kitware.com
Subject: [vtkusers] Help with linking C++ native code for Java JNI


Hello everyone,
 
Following a recent post, I thought I would try writing some C++ code which
will had back an array to Java. Whilst I can get basic "Hello World" type
JNI programs to work, I've having difficulty in doing anything that uses
vtk-based methods for Java. On linking a program which uses vtkJavaUtils.h,
e.g. to invoke the vtkJavaGetPointerFromObject() method, I get the following
error:
 
error LNK2001: unresolved external symbol "void * __cdecl
vtkJavaGetPointerFromObject(struct JNIEnv_ *,class jobject *,char *)"
(?vtkJavaGetPoi nterFromObject@@YAPAXPAUJNIEnv_@@PAV_jobject@@PAD at Z
<mailto:?vtkJavaGetPointerFromObject@@YAPAXPAUJNIEnv_@@PAV_jobject@@PAD at Z> )

Does anyone know which .lib file the vtkJavaUtil code have been incorporated
in? I thought I was including all of those required. I get the same error
through Visual C++ IDE and from the 'cl' command-line approach.
 
Any advice much appreciated,
Greg
 
 
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030606/a5a89d03/attachment.htm>


More information about the vtkusers mailing list