This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Link errors: Confused about calling C code from GCJ via jni


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,
 

extern 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

Then  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]