delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/05/07/14:50:16

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RFC_ABUSE_POST,SPF_HELO_PASS,TW_NW,T_RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
X-Trace: 608902282/mk-filter-4.mail.uk.tiscali.com/B2C/$b2c-THROTTLED-DYNAMIC/b2c-CUSTOMER-DYNAMIC-IP/85.210.86.146/None/cp DOT montanari AT tiscali DOT co DOT uk
X-SBRS: None
X-RemoteIP: 85.210.86.146
X-IP-MAIL-FROM: cp DOT montanari AT tiscali DOT co DOT uk
X-SMTP-AUTH:
X-Originating-Country: GB/UNITED KINGDOM
X-MUA: Mutt/1.5.21 (2010-09-15)
X-IP-BHB: Once
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AvsEALqTxU1V0laS/2dsb2JhbACmI3ikb55Cgi2DXwSTf4pE
Date: Sat, 7 May 2011 19:49:47 +0100
From: christian Montanari <cp DOT montanari AT tiscali DOT co DOT uk>
To: cygwin AT cygwin DOT com
Subject: UnsatisfiedLinkError:with gcc linked cyg.dll under J AT v@-1.6
Message-ID: <20110507184947.GA9140@thorntonmontanari.co.uk>
MIME-Version: 1.0
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

many are not using gnu-java, the orginial sun-java, it is certainly more baroc !

anyway, I am trying to link a DLL with gcc then to load it with
Java(TM) system.loadlibray() but got eventually the error...
...
[Loaded java.lang.UnsatisfiedLinkError from shared objects file] 
...

I have attached a benchmark taken from the archives...
<http://cygwin.com/ml/cygwin/2003-02/msg02235.html>
and run "make test",

I wonder what is the missing command in the linker which allows JNI to
load all the cygwin objects?

Christian Montanari.
 

---------------HelloWorld.java-------
public class HelloWorld
{
  private static String libraryName = "Native";
 
  /**
   * Failure callback strategy that writes a message to sysout, then
   calls
   * System.exit(1). 
   */
  public static Runnable EXIT_JVM = new Runnable() {
    public void run() {
      System.out.println("Could not load '" + libraryName + "'");
      System.out.println("java.library.path = " 
          + System.getProperty("java.library.path"));
      System.exit(1);
    }
  };
  public static Runnable THROW_ERROR = new Runnable() {
    public void run() {
      throw new UnsatisfiedLinkError("Could not load '" + libraryName
      + "'");
    }
  };
  private static Object callbackLock = new Object();
  private static Runnable failureCallback = EXIT_JVM;

  private static native void sayHello();

  public static void main( String[] args )
  {
      try {
        //System.loadLibrary( libraryName , true);
	  System.loadLibrary( libraryName );
      } catch (UnsatisfiedLinkError e) {
        synchronized (callbackLock) {
	      if (failureCallback != null) {
	      	   failureCallback.run();
		         }
			   }
      }
    sayHello();
  }
}
------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;
}
------Makefile-----just do make test
JAVA_HOME?='c:/PROGRA~1/Java/jdk1.6.0_24'
clean:
	set nonomatch;\
	rm -rf  ./bin Native.dll *.o *_jni.h

HelloWorld.class: HelloWorld.java
		  javac HelloWorld.java

HelloWorld_jni.h :HelloWorld.class
		 javah -classpath . -o HelloWorld_jni.h HelloWorld

Native.dll: HelloWorld.c HelloWorld_jni.h Makefile
	    $(CXX) \
	      -D_REENTRANT -D_GNU_SOURCE -D__int64='long long'  \
	        -I${JAVA_HOME}/include -I${JAVA_HOME}/include/win32
		-I. \
		$< $(LDFLAGS) -o $@


Native.dll:LDFLAGS=-mno-cygwin
Native.dll:LDFLAGS=-shared 
Native.dll:LDFLAGS=-shared -Wl,--add-stdcall-alias
Native.dll:LDFLAGS=-shared
-Wl,--verbose,--warn-unresolved-symbols,--add-stdcall-alias
Native.dll:LDFLAGS=-shared
-Wl,--verbose,--warn-unresolved-symbols,--add-stdcall-alias,--add-indirect
Native.dll:LDFLAGS=-shared
-Wl,--verbose,--warn-unresolved-symbols,--add-stdcall-alias,--add-stdcall-underscore
Native.dll:LDFLAGS=-shared
-Wl,--verbose,--warn-unresolved-symbols,--add-stdcall-alias,--add-underscore
Native.dll:LDFLAGS=-shared
-Wl,--verbose,--error-unresolved-symbols,--add-stdcall-alias
--add-underscore
Native.dll:LDFLAGS=-shared
-Wl,--verbose,--error-unresolved-symbols,--add-stdcall-alias,--export-dynamic

Native.dll:CXX=
Native.dll:CXX=g++ --verbose

comma:= ,
semicomma:= ;
empty:=
space:= $(empty) $(empty)

test:LD_LIBRARY_PATH:=$(subst $(space),$(semicomma),$(addprefix
'c:/cygwin',/usr/lib/gcc/i686-pc-cygwin/4.3.4
/usr/lib/gcc/i686-pc-cygwin/4.3.4
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../ /lib/ /usr/lib/))
test: Native.dll
      LD_LIBRARY_PATH="$(LD_LIBRARY_PATH)" java -verbose -classpath
      . -Xmx256m -Djava.library.path=. HelloWorld


ifneq (,)
 nm -u Native.dll 
         w __Jv_RegisterClasses
         w __ZdaPv
         w __ZdaPvRKSt9nothrow_t
         w __ZdlPv
         w __ZdlPvRKSt9nothrow_t
         w __Znaj
         w __ZnajRKSt9nothrow_t
         w __Znwj
         w __ZnwjRKSt9nothrow_t
         U ___crt_xc_end__
         U ___crt_xc_start__
         U ___crt_xi_end__
         U ___crt_xi_start__
         U ___crt_xl_start__
         U ___crt_xp_end__
         U ___crt_xp_start__
         U ___crt_xt_end__
         U ___crt_xt_start__
         U ___tls_end__
         U ___tls_start__
         U __end__
endif



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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