delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/02/27/16:21:31

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Spam-Filter: check_local AT alphatech DOT com 4.4(020923:1754) http://digitalanswers.org/
Message-Id: <4.3.2.7.2.20030227132021.00b74ec8@mail.alphatech.com>
X-Sender: alant AT mail DOT alphatech DOT com
Date: Thu, 27 Feb 2003 13:21:00 -0800
To: <cygwin AT cygwin DOT com>
From: Alan Thompson <athompson AT alphatech DOT com>
Subject: Re: LD_LIBRARY_PATH not accessible through java under cygwin
for JNI
In-Reply-To: <BHEPLBGHPJKIDJGHBFLIAEABCAAA.gbourgeois@yaccom.com>
Mime-Version: 1.0

Gilles - The following should work for you under Cygwin:

HelloWorld.c:
-----------------------------------------------------------------
#include <iostream>
using namespace std;

#include "HelloWorld_jni.h"

JNIEXPORT void JNICALL
Java_HelloWorld_sayHello( JNIEnv *env, jclass c )
{
  cerr << "Hello World from C!" << endl;
}


HelloWorld.java
--------------------------------------------------------------------
public class HelloWorld
{
  private static native void sayHello();
  public static void main( String[] args )
  {
    System.loadLibrary( "Native" );
    sayHello();
  }
}


go.csh:
------------------------------------------------------------------------------------
#!/bin/tcsh -v

set nonomatch
rm -rf  ./bin
rm -f   Native.dll *.o *.h

javac HelloWorld.java

javah -classpath . -o HelloWorld_jni.h HelloWorld

g++ \
  -D_REENTRANT -D_GNU_SOURCE -D__int64='long long'  \
  -I${JAVA_HOME}/include -I${JAVA_HOME}/include/win32 \
  -I. \
  -Wl,--add-stdcall-alias -shared -o Native.dll HelloWorld.c

java -classpath . -Xmx256m -Djava.library.path=. HelloWorld
--------------------------------------------------------------------------------------


Make the 3 files indicated, type "go.csh", and it should work.  This assumes you have java (I use java 1.4.1) installed on your machine,  and that the environment variable JAVA_HOME is set to point to it (e.g. setenv JAVA_HOME c:/j2sdk1.4.1" or similar).

You should also checkout the excellent webpage on using JNI with Cygwin at:  
	http://www.inonit.com/cygwin/

Alan Thompson




At 12:28 PM 2/27/2003 +0100, you wrote:
hi folks,
I am currently using my JNI so/dll library under solaris, linux and cygwin.
with solaris and linux, no problem, I bind to it using load(..) since the
LD_LIBRARY_PATH is set.
BUT, under cygwin/windows, it does not work and I shall tell the absolute
path when I load the library.
I hav already posted in java.machine, but Randall schulz told  me to try in
this mailing list.
thanks for help
gilles


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019