Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jul 1999 11:36:35 -0500 (EST)
From:      Gunther Schadow <gunther@aurora.rg.iupui.edu>
To:        freebsd-java@FreeBSD.ORG, larsene@bahay.rn.byu.edu
Subject:   Re: jni
Message-ID:  <199907291636.LAA28005@aurora.rg.iupui.edu>

next in thread | raw e-mail | index | archive | help
Scott,

you are missing _pure_virtual() which is part of the core gcc library
(/usr/lib/libgcc).  BTW it's only needed for C++ and is an error
handler for a call to a function declared in an abstract class that
has no implementation.

I usually circumvent these problems of missing references in shared
libraries by not relying on GCC/G++ to do the work for me. Instead I
am compiling to *.so files with "-fPIC -c" and then I use -ld to have
contol over the link step, so as to include any extra library that I
need. Actually, when I first did shared libraries on FreeBSD the GCC
 -shared support never worked for me, but ld -Bshareable was always
fine.

For example, the following is a snippet of my Makefile that builds a
JNI wrapper around GDBM.

libjdbm.so: jdbm_Database.o
        ld -Bshareable -o $@ jdbm_Database.o -L/usr/local/lib -lgdbm 

jdbm_Database.o: jdbm_Database.c
        gcc -O2 -fpic -I/usr/local/include -c jdbm_Database.c

This works for me. In your case, you need to make sure that -lgcc is
linked to your .so file.

In earlier times I have used the true partial link feature of ld (see
ld(1) option -r) to resolve dependencies early when building a
library. That's a nice feature when you want to distribute a library
but you want to avoid your clients to bother with all the billions of
dependent libraries (Have you ever linked against an Oracle 7 library?
then you know what I mean.)

hope this helps,
-Gunther

Gunther Schadow ----------------------------------- http://aurora.rg.iupui.edu
Regenstrief Institute for Health Care
1001 W 10th Street RG5, Indianapolis IN 46202, Phone: (317) 630 7960
schadow@aurora.rg.iupui.edu ---------------------- #include <usual/disclaimer>


E. Scott Larsen <larsene@bahay.rn.byu.edu> wrote:
> I'm looking into using the JNI for an upcoming project, and hava a
> question about using on
> FreeBSD.  I'm doing a very simple example (code for each file is below)
> from the Essential
> JNI (Rob Gordon, Prentace Hall...).  I'm running  FreeBSD-3.2-Stable
> about a week old;
> jdk1.1.8 just re-installed fresh this morning from cvsup'd ports, and
> using the csh:
>
> > cd /home/larsene/jni
> > setenv LD_LIBRARY_PATH /home/larsene/jni:/usr/lib:/usr/local/lib
> > rm *.o lib*
> > g++ -c -fPIC *.c -I$JDK/include -I$JDK/include/freebsd
> > g++ -shared -o libmylib.so -fPIC *.o
> > java main
> /usr/lib/libg++.so.4: Undefined symbol "__pure_virtual" (libmylib.so)
> my error
> >
> I assume the problem is something missing from that LD..PATH setting, or
> perhaps a
> compiler flag.  Anyone got a quick tip or a pointer to somewhere I aught
> to look?  Thanks
> tons!!!
>
> // file: main.java
> public class main {
>          static {
>                   try {
>                                 System.loadLibrary("mylib");
>                   } catch (Error e) {
>                                 System.out.println("my error");
>                                 System.exit(0);
>                   }
>          }
>          public static void main(String[] args) {
>                   aclass        c = new aclass();
>                   c.theNativeMethod();
>          }
> }
> //file: aclass.java
> public class aclass {
>          public native void theNativeMethod();
>          public void aJavaMethod() {
>                   theNativeMethod();
>          }
> }
> //file: aclass.c
> #include <stdio.h>
> #include "aclass.h"
> JNIEXPORT void JNICALL  Java_aclass_theNativeMethod
>          (JNIEnv* env, jobject thisObj)  {
>          printf("Hello Scott World\n");
> }
> //file: aclass.h  ////generated by >javac aclass.java ; javah -jni
> aclass
> /* DO NOT EDIT THIS FILE - it is machine generated */
> #include <jni.h>
> /* Header for class aclass */
> #ifndef _Included_aclass
> #define _Included_aclass
> #ifdef __cplusplus
> extern "C" {
> #endif
> /*
>  * Class:     aclass
>  * Method:    theNativeMethod
>  * Signature: ()V
>  */
> JNIEXPORT void JNICALL Java_aclass_theNativeMethod
>   (JNIEnv *, jobject);
> #ifdef __cplusplus
> }
> #endif
> #endif




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907291636.LAA28005>