[JNI]Een andere linker error???

Pagina: 1
Acties:

  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 01:32

Gonadan

Admin Beeld & Geluid, Harde Waren
Topicstarter
En nu ben ik dus gefrustreerd :(

Ik probeer native code te laten uitvoeren door java.
Ik heb een mooi boekje van java gedownload (deze) en precies gedaan wat daarin stond.

HelloWorld.java
Java:
1
2
3
4
5
6
7
8
9
class HelloWorld {
        public native void print();
        public static void main(String[] args) {
                new HelloWorld().print();
        }
        static {
                System.loadLibrary("HelloWorld");
        }
}

Compilen met:
javac HelloWorld.java

Header maken met:
javah -jni HelloWorld
geeft deze header file:
C:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorld
 * Method:    print
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorld_print
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Dan maken we de volgende C file
C:
1
2
3
4
5
6
7
8
9
10
#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"

JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
    printf("HelloWorld!\n");
    return;                             
}

Dan die compilen
gcc -c HelloWorld.c -o HelloWorld.o -Ih:\java\include -Ih:\java\include\win32
Een dll'tje bakken
gcc -shared --kill-at -o HelloWorld.dll HelloWorld.o

Dit gaat allemaal goed zonder foutmeldingen.
Alleen zodra ik hem start:
java HelloWorld

Krijg ik dit:
code:
1
2
3
Exception in thread "main" java.lang.UnsatisfiedLinkError: print
        at HelloWorld.print(Native Method)
        at HelloWorld.main(HelloWorld.java:4)

Het is niet zo dat java.library.path verkeerd staat ofzo, want hij vindt de dll wel. Anders krijg je namelijk die 'library not found at'-error.
Het lijkt wel alsof hij de methode niet leuk vindt ofzo.
Kan het aan de compiler liggen?
Alle hulp is welkom ;)

[ Voor 4% gewijzigd door Gonadan op 23-02-2006 09:23 ]

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8


  • Gonadan
  • Registratie: Februari 2004
  • Laatst online: 01:32

Gonadan

Admin Beeld & Geluid, Harde Waren
Topicstarter
Update:
Het is me dan toch eindelijk gelukt, het bleek dat --kill-at niet werkte dus dat ik het handmatig moest doen via een .def. Vrij irritant als overal staat dat --kill-at de oplossing is 8)7

Look for the signal in your life, not the noise.

Canon R6 | RF 24-70 f/2.8 L | 50 f/1.8 STM | 430EX II
Sigma 85 f/1.4 Art | 100-400 Contemporary
Zeiss Distagon 21 f/2.8