JNI Problems with MINGW32

G

grobe0ba

I'm trying to compile a DLL with MINGW32 for JNI. I keep getting
UnsatisfiedLinkErrors whenever I try running the class. It works fine
MS VC compiler from the .NET 1.1 SDK. If someone can tell me the
(probably obvious) thing I'm doing wrong, I'd be very grateful.

I'm using two different versions of my Makefile to link it. One using
ld, one doing it through gcc...

Here is the Java class from tst.java:

class tst
{
public native void c_tst();
static
{
System.loadLibrary("tst");
}

public static void main(String args[])
{
tst x = new tst();
x.c_tst();
}
}

Here is the C code from tst.c:

#include "tst.h"
JNIEXPORT void JNICALL Java_tst_c_1tst(JNIEnv *env, jobject obj)
{
return;
}


Here is the output from my Makefile:

javac tst.java
javah -jni tst
gcc -g3 -Q -c -otst.o tst.c
getc putc getchar putchar fopen64 ftello64 vsnwprintf Java_tst_c_1tst
Execution times (seconds)
lexical analysis : 0.02 (35%) usr 0 kb ( 0%)
ggc
symout : 0.01 (33%) usr 346 kb (21%)
ggc
TOTAL : 0.05 1616 kb
dlltool -e exports.o --dllname tst tst.o
dlltool -l tst.a --dllname tst tst.o
ld -format pei-i386 -shared --dynamic-list-data --dll --add-stdcall-
alias --export-all-symbols --output-def tst.def -L/mingw/lib -l crtdll
-otst.dll tst.o exports.o

Here is the output from the JVM:

java.lang.UnsatisfiedLinkError: C:\MSYS\home\Administrator\java
\tst.dll: A dynamic link library (DLL) initialization routine failed
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at tst.<clinit>(tst.java:6)
Exception in thread "main"

The only difference between the two Makefiles is instead of ld --
format .... becomes:
gcc -g3 -Q -shared -otst.dll tst.o exports.o

When I use that, the JVM outputs

Exception in thread "main" java.lang.UnsatisfiedLinkError: c_tst
at tst.c_tst(Native Method)
at tst.main(tst.java:12)


As I said earlier, I'm probably doing something obviously wrong, so
any suggestions would help.
TIA.
 
A

Arne Vajhøj

I'm trying to compile a DLL with MINGW32 for JNI. I keep getting
UnsatisfiedLinkErrors whenever I try running the class. It works fine
MS VC compiler from the .NET 1.1 SDK. If someone can tell me the
(probably obvious) thing I'm doing wrong, I'd be very grateful.

I'm using two different versions of my Makefile to link it. One using
ld, one doing it through gcc...

Here is the Java class from tst.java:

class tst
{
public native void c_tst();
static
{
System.loadLibrary("tst");
}

public static void main(String args[])
{
tst x = new tst();
x.c_tst();
}
}

Here is the C code from tst.c:

#include "tst.h"
JNIEXPORT void JNICALL Java_tst_c_1tst(JNIEnv *env, jobject obj)
{
return;
}


Here is the output from my Makefile:

javac tst.java
javah -jni tst
gcc -g3 -Q -c -otst.o tst.c
getc putc getchar putchar fopen64 ftello64 vsnwprintf Java_tst_c_1tst
Execution times (seconds)
lexical analysis : 0.02 (35%) usr 0 kb ( 0%)
ggc
symout : 0.01 (33%) usr 346 kb (21%)
ggc
TOTAL : 0.05 1616 kb
dlltool -e exports.o --dllname tst tst.o
dlltool -l tst.a --dllname tst tst.o
ld -format pei-i386 -shared --dynamic-list-data --dll --add-stdcall-
alias --export-all-symbols --output-def tst.def -L/mingw/lib -l crtdll
-otst.dll tst.o exports.o

Here is the output from the JVM:

java.lang.UnsatisfiedLinkError: C:\MSYS\home\Administrator\java
\tst.dll: A dynamic link library (DLL) initialization routine failed
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at tst.<clinit>(tst.java:6)
Exception in thread "main"

The only difference between the two Makefiles is instead of ld --
format .... becomes:
gcc -g3 -Q -shared -otst.dll tst.o exports.o

When I use that, the JVM outputs

Exception in thread "main" java.lang.UnsatisfiedLinkError: c_tst
at tst.c_tst(Native Method)
at tst.main(tst.java:12)


As I said earlier, I'm probably doing something obviously wrong, so
any suggestions would help.

I use:

gcc -c -I\myjava\include -I\myjava\include\win32 mypack_MyClass.c -o
mypack_MyClass.obj
gcc -s -shared -Wl,--export-all,--kill-at mypack_MyClass.obj -o mylib.dll

Arne
 
G

grobe0ba

I'm trying to compile a DLL with MINGW32 for JNI. I keep getting
UnsatisfiedLinkErrors whenever I try running the class. It works fine
MS VC compiler from the .NET 1.1 SDK. If someone can tell me the
(probably obvious) thing I'm doing wrong, I'd be very grateful.
I'm using two different versions of my Makefile to link it. One using
ld, one doing it through gcc...
Here is the Java class from tst.java:
class tst
{
    public native void c_tst();
    static
    {
        System.loadLibrary("tst");
    }
    public static void main(String args[])
    {
        tst x = new tst();
        x.c_tst();
    }
}
Here is the C code from tst.c:
#include "tst.h"
JNIEXPORT void JNICALL Java_tst_c_1tst(JNIEnv *env, jobject obj)
{
    return;
}
Here is the output from my Makefile:
javac tst.java
javah -jni tst
gcc -g3 -Q -c -otst.o tst.c
 getc putc getchar putchar fopen64 ftello64 vsnwprintf Java_tst_c_1tst
Execution times (seconds)
 lexical analysis        :    0.02 (35%) usr        0      kb  ( 0%)
ggc
 symout                    :    0.01 (33%) usr       346   kb  (21%)
ggc
 TOTAL                    :    0.05                       1616 kb
dlltool -e exports.o --dllname tst tst.o
dlltool -l tst.a --dllname tst tst.o
ld -format pei-i386 -shared --dynamic-list-data --dll --add-stdcall-
alias --export-all-symbols --output-def tst.def -L/mingw/lib -l crtdll
-otst.dll tst.o exports.o
Here is the output from the JVM:
java.lang.UnsatisfiedLinkError: C:\MSYS\home\Administrator\java
\tst.dll: A dynamic link library (DLL) initialization routine failed
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at tst.<clinit>(tst.java:6)
Exception in thread "main"
The only difference between the two Makefiles is instead of ld --
format .... becomes:
gcc -g3 -Q -shared -otst.dll tst.o exports.o
When I use that, the JVM outputs
Exception in thread "main" java.lang.UnsatisfiedLinkError: c_tst
    at tst.c_tst(Native Method)
    at tst.main(tst.java:12)
As I said earlier, I'm probably doing something obviously wrong, so
any suggestions would help.

I use:

gcc -c -I\myjava\include -I\myjava\include\win32 mypack_MyClass.c -o
mypack_MyClass.obj
gcc -s -shared -Wl,--export-all,--kill-at mypack_MyClass.obj -o mylib.dll

Arne- Hide quoted text -

- Show quoted text -

Thanks Arne! That solved it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top