Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java <-> C++ communication

0 views
Skip to first unread message

Michael Niechziol

unread,
Nov 4, 1996, 3:00:00 AM11/4/96
to

Hello,

I'm forced to use (quite hudge) C++ libraries in my java-programms.
I know about the possibility to use native-Methods, but this does't seem
to be a solution for me...

My problem is, that java (the virt. machine) can use the native
functions
that I defined in the shared-lib, but no functions that are defined
beyond
that shared-lib (e.g. a 'cout').

Here ist the simple HelloWorld example:

in HelloWorld.java:
(plus the javah generated HelloWorld.c, HelloWorld.h)

class HelloWorld {
public native void displayHelloWorld();

static {
System.loadLibrary("hello");
}
}

in HelloWorldImp.c (implemetation):

#include <StubPreamble.h>
#include "HelloWorld.h"
#include <stdio.h>
/* #include <iostream.h> */

void HelloWorld_displayHelloWorld(struct HHelloWorld *thing) {
printf("Hello C World!\n");
/* cout << "Hello C++ World\n"; */
return;
}

and the file Main.java:

class Main {
public static void main(String args[]) {
new HelloWorld().displayHelloWorld();
}
}

I complile everithins with gcc -G HelloWorld.c HelloWorldImp.c -o
libhello.so -I/usr/local/java/include -I/usr/local/java/include/solaris

So far, so well. "java Main" produces the desired output
"Hello C World!". But if I uncomment the line including "cout"
(and of course the #include...) I can compile everything without errors
but "java Main" produces the following:

ld.so.1: /usr/local/java/bin/../bin/sparc/java: fatal: relocation error:
symbol not found: __ls__7ostreamPCc: referenced in
/globals/di/minie/Dipl/Java/native/HelloWorld/libhello.so
(/globals/di/minie/Dipl/Java/native/HelloWorld/libhello.so)
java.lang.UnsatisfiedLinkError: no hello in shared library path
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at HelloWorld.<clinit>(HelloWorld.java:5)
at
java.lang.UnsatisfiedLinkError: displayHelloWorld
at Main.main(Main.java:3)

How can I tell Java where the 'cout' is defined ?
By the way the lib libhello.so is in the same directory as Main.java
(and
the other files) and beyond that I set LD_LIBRARY_PATH to this
directory.

As you can seen I'm working with Solaris.
I hope somebody can help me.

Michael...
--
+--------------------------------+-------------------------------------+
| Michael Niechziol | email: mi...@uni-paderborn.de |
| 33104 Paderborn / Germany | mi...@c-lab.de |
+--------------------------------+-------------------------------------+

0 new messages