From owner-freebsd-java Wed Mar 15 15:44:18 2000 Delivered-To: freebsd-java@freebsd.org Received: from ns.yogotech.com (ns.yogotech.com [206.127.79.126]) by hub.freebsd.org (Postfix) with ESMTP id 0F1C337BC69 for ; Wed, 15 Mar 2000 15:44:15 -0800 (PST) (envelope-from nate@yogotech.com) Received: from nomad.yogotech.com (nomad.yogotech.com [206.127.79.115]) by ns.yogotech.com (8.9.3/8.9.3) with ESMTP id QAA02803; Wed, 15 Mar 2000 16:44:07 -0700 (MST) (envelope-from nate@nomad.yogotech.com) Received: (from nate@localhost) by nomad.yogotech.com (8.8.8/8.8.8) id QAA11714; Wed, 15 Mar 2000 16:44:06 -0700 (MST) (envelope-from nate) Date: Wed, 15 Mar 2000 16:44:06 -0700 (MST) Message-Id: <200003152344.QAA11714@nomad.yogotech.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Chad David Cc: Keith Wong , freebsd-java Subject: Re: JNI and Shared Library In-Reply-To: References: <38CAAFC3.FE74A64D@1connect.com> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Reply-To: nate@yogotech.com (Nate Williams) Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > I do not completely understand all that you have said, but hopefully this > will help (it may be more than you asked for): > > Step 1) Java source > > public class Beep { > public static native void beep(int count); > } > static { > System.loadLibrary("beep"); > } > > public static void main(String args[]) { > beep(4); > } > } > > Step 2) Compile the class and generate header > > javac Beep.java > javah -jni Beep.class > > Step 3) C Source > > include > include > #include "Beep.h" /* generated file */ > > JNIEXPORT void JNICALL > Beep_beep(JNIEnv *e, jclass c, jint count) { > int i = (int)count; > > for ( ; i > 0; i--) { > printf("%c", 7); > fflush(stdout); > usleep(300000); > } > return; > } > > Step 4) Compile and link that C code > > cc -Wall -c beep.c -I(the paths for your env) Make sure you compile with -fPIC for the compiler as well. cc -fPIC -Wall -c beep.c -I(the paths for your env) > ld -Bshareable -fPIC -o libbeep.so beep.o > > Step 5) Set your LD_LIBRARY_PATH > > export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD > > Step 6) Run the program > > java Beep > > I hope this helps (and I didn't miss anything). Great instructions Chad, thanks! Nate To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message