This is the mail archive of the
cygwin
mailing list for the Cygwin project.
UnsatisfiedLinkError:with gcc linked cyg.dll under J@v@-1.6
- From: christian Montanari <cp dot montanari at tiscali dot co dot uk>
- To: cygwin at cygwin dot com
- Date: Sat, 7 May 2011 19:49:47 +0100
- Subject: UnsatisfiedLinkError:with gcc linked cyg.dll under J@v@-1.6
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