Cygnus Native Interface

Ross Creech rcreech@nortelnetworks.com
Thu Sep 30 10:23:00 GMT 1999


Hello:

I am implementing an interface between C++ and Java code using the Cygnus
Native Interface (CNI). I have already implemented an interface utilizing
the Java Native Inteface (JNI); however, CNI is more efficient. We have
licensed (or in the process of licensing) the GCJ run-time environment for
our new product. Unfortunately, I am having difficulties accessing arrays. I
am wondering if my code is wrong, if the libgcj library is out of date, or
something else entirely I would appreciate any help you can provide.

Below is some source code:

File - CNIInterface.java

public class CNIInterface {

   /* Default Constructor */
     
   public CNIInterface() { };
     
   public native boolean cDecode(byte[] buffer, short bufferSize);
          
}

File - CCImpl.cc

#include <cni.h>
#include <iostream.h>
#include "CNIInterface.h"

jboolean CNIInterface::cDecode(jbyteArray buffer, jshort bufferSize)
{

   jsize              array_length;
   jint               size = 10;
   jintArray          myArray = JvNewIntArray(size);  // THIS WORKS!!

// jbyte *bytep = elements (buffer); // THIS DOESN'T WORK!!

// array_length = JvGetArrayLength(myArray);  // THIS DOESN'T WORK!!
// array_length = JvGetArrayLength(buffer);  // THIS DOESN'T WORK!!

   cout << "The array size = " << array_length << endl;

}

The lines marked with "THIS DOESN'T WORK" actually compile fine; however, I
receive the following error when linking. What's interesting is that
creating the new array of itegers compiles/links fine; I just can't access
the elements or the array size.

>/opt/bin/gcj --main=CNITester *.o -L/opt/lib -lgcj  -lstdc++ 
CCImpl.o: In function `JArray<int> type_info function':
/home/rcreech/stack/javacni/CCImpl.cc(.gnu.linkonce.t.__tft6JArray1Zi+0x24):
undefined reference to `__JArray type_info function'
/home/rcreech/stack/javacni/CCImpl.cc(.gnu.linkonce.t.__tft6JArray1Zi+0x24):
relocation truncated to fit: R_PPC_REL24 __JArray type_info function
/home/rcreech/stack/javacni/CCImpl.cc(.gnu.linkonce.t.__tft6JArray1Zi+0x3e):
undefined reference to `__JArray type_info node'
/home/rcreech/stack/javacni/CCImpl.cc(.gnu.linkonce.t.__tft6JArray1Zi+0x42):
undefined reference to `__JArray type_info node'
collect2: ld returned 1 exit status

>ll /opt/lib
total 17995
drwxrwxr-x   3 minyard  minyard      1024 Dec 25 22:31 .
drwxr-xr-x  12 minyard  minyard      1024 Sep  1  1999 ..
drwxrwxr-x   3 minyard  minyard      1024 Jul 29  1999 gcc-lib
-rw-r--r--   1 minyard  minyard   5855696 Aug 27  1999 libgcj.a
-rwxr-xr-x   1 minyard  minyard       630 Aug 27  1999 libgcj.la
lrwxrwxrwx   1 minyard  minyard        15 Sep  7  1999 libgcj.so ->
libgcj.so.0.0.0
lrwxrwxrwx   1 minyard  minyard        20 Sep  7  1999 libgcj.so.0 ->
libgcj.so.0.0.0.keep
-rwxr-xr-x   1 minyard  minyard   4165356 Aug 27  1999 libgcj.so.0.0.0
-rw-rw-r--   1 minyard  minyard   4413650 Dec 25 19:06 libgcj.so.0.0.0.keep
-rw-r--r--   1 minyard  minyard       216 Aug 27  1999 libgcj.spec
-rw-r--r--   1 minyard  minyard    685020 Aug 27  1999 libgcjgc.a
-rwxr-xr-x   1 minyard  minyard       642 Aug 27  1999 libgcjgc.la
lrwxrwxrwx   1 minyard  minyard        17 Sep  7  1999 libgcjgc.so ->
libgcjgc.so.0.0.0
lrwxrwxrwx   1 minyard  minyard        17 Sep  7  1999 libgcjgc.so.0 ->
libgcjgc.so.0.0.0
-rwxr-xr-x   1 minyard  minyard    294251 Aug 27  1999 libgcjgc.so.0.0.0
-rw-r--r--   1 minyard  minyard    316342 Aug 20  1999 libiberty.a
lrwxrwxrwx   1 root     root           18 Dec 25 22:31 libstdc++.a ->
libstdc++.a.2.10.0
-rw-r--r--   1 minyard  minyard   2143662 Aug 20  1999 libstdc++.a.2.10.0
-rw-r--r--   1 minyard  minyard    304718 Aug 27  1999 libzgcj.a
-rwxr-xr-x   1 minyard  minyard       636 Aug 27  1999 libzgcj.la
lrwxrwxrwx   1 minyard  minyard        16 Sep  7  1999 libzgcj.so ->
libzgcj.so.0.0.0
lrwxrwxrwx   1 minyard  minyard        16 Sep  7  1999 libzgcj.so.0 ->
libzgcj.so.0.0.0
-rwxr-xr-x   1 minyard  minyard    151755 Aug 27  1999 libzgcj.so.0.0.0

Many thanks,

Ross Creech
MTX Networking and Services
972-685-7479 (ESN 445)
rcreech@nortelnetworks.com



More information about the Java mailing list