Date: Wed, 15 Mar 2000 16:44:06 -0700 (MST) From: Nate Williams <nate@yogotech.com> To: Chad David <davidc@acns.ab.ca> Cc: Keith Wong <keith@1connect.com>, freebsd-java <freebsd-java@FreeBSD.ORG> Subject: Re: JNI and Shared Library Message-ID: <200003152344.QAA11714@nomad.yogotech.com> In-Reply-To: <Pine.BSF.4.21.0003151357100.34452-100000@lodge.guild.ab.ca> References: <38CAAFC3.FE74A64D@1connect.com> <Pine.BSF.4.21.0003151357100.34452-100000@lodge.guild.ab.ca>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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 <stdio.h>
> include <unistd.h>
> #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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003152344.QAA11714>
