Link errors: Confused about calling C code from GCJ via jni
Barnet Wagman
wagman@enteract.com
Sun Jan 14 09:50:00 GMT 2001
Please excuse the elementary nature of this question: I've searched the
archives, FAQ, etc. and not found the answer to my problem.
I'm trying to callÃÂ C (not C++) functions from GCJ compiled Java
via jni (these are functions I'm currently using with regular interpreted
Java, which is why I'd prefer not to switch to CNI).ÃÂ I ran gcjh and
recompiled the C functions (with the -D_REENTRANT option) and put the binaries
into a library ('ld -shared ...')
The header generated by gcjh looks like C to me, but when I try to link
this library against gcj compiled java, it looks as if gcj is looking for
C++.
I.e. from my class Locfit.java, gcjh generates names for two functions,
ÃÂ
e xtern void Java_locfit_Locfit_jniLocfit (
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
JNIEnv *env, jobject, jint,
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
jdoubleArray,,jdoubleArray, jdouble, jint, jint, jint, jdoubleArray);
extern void Java_locfit_Locfit_jniSetup (JNIEnv *env, jclass);
They refer to two C functions in one file, which gets compiled and put
into library liblocfit.so
T henÃÂ after compiling the calling java classes
gcj -c --no-bounds-check -O3 -g0 SimRunner.java
gcj -c --no-bounds-check -O3 -g0 Locfit.java
linking
gcj --main=liveT.SimRunner -o SimRunner SimRunner.o Locfit.o
liblocfit.so
ÃÂ
yields the error messages
ÃÂ
/home/moi/JavaTree/locfit/Locfit.o: In function `locfit::Locfit::_003cclinit_003e(unsigned)':
/home/moi/JavaTree/locfit/Locfit.o(.text+0x383): undefined reference
to `locfit::Locfit::jniSetup(void)'
/home/moi/JavaTree/locfit/Locfit.o(.data+0x20c): undefined reference
to `locfit::Locfit::jniLocfit(int, JArray<double> *, JArray<double>
*, double, int, int, int, JArray<double> *)'
/home/moi/JavaTree/locfit/Locfit.o(.data+0x21c): undefined reference
to `locfit::Locfit::jniSetup(void)'
/home/moi/JavaTree/locfit/Locfit.o(.data+0x29c): undefined reference
to `locfit::Locfit::jniLocfit(int, JArray<double> *, JArray<double>
*, double, int, int, int, JArray<double> *)'
collect2: ld returned 1 exit status
make: *** [SimRunner] Error 1
ÃÂ
It looks like the linker is looking for C++ references.ÃÂ ÃÂ Of
course in the library, the names are
00057380 T Java_locfit_Locfit_jniLocfit
000576b0 T Java_locfit_Locfit_jniSetup
ÃÂ
I'd greatly appreciate any suggestions about how to get this working.
Thanks,
Barnet Wagman
More information about the Java
mailing list