I am getting an error when compiling the shared library for this JNI code.
Any input or advice is needed. JNI is new to me, and OE ( operator errors
) are more than likely to blame. I am however concerned because this exact
code works fine on NT4.0, using Visual C++ 5.0 Compiler.
OS: Redhat 6.0
JDK Version: JDK1.1.7B
Lib Version: lib2.1
Shell: bash
Java Source
/**********************************/
public class HelloWorld{
public native void displayHelloWorld();
static{
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}//end class
/**********************************/
C Header
/**********************************/
/* 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: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
/**********************************/
C Source
/**********************************/
#include "HelloWorld.h"
#include <jni.h>
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_speakInC(JNIEnv *env, jobject obj){
printf("Greetings From the C-JNI World!!!\n");
return;
}
/**********************************/
Shared Library Command:
cc -I/usr/local/jdk117/include -I/usr/local/jdk117/include/genunix
HellWorldNative.c -o libhello.so
Compile Warning:
HellWorldNative.c: In function `main':
HellWorldNative.c:12: warning: return type of `main' is not `int'
Core Dump Error:
[sgee@maxor jni]# java HelloWorld
SIGSEGV 11* segmentation violation
stackbase=0xbffff8e0, stackpointer=0xbffff7e0
Full thread dump:
"Finalizer thread" (TID:0x406c0210, sys_thread_t:0x41404e0c, state:R)
prio=1
"Async Garbage Collector" (TID:0x406c0258, sys_thread_t:0x413e3e0c,
state:R) prio=1
"Idle thread" (TID:0x406c02a0, sys_thread_t:0x413c2e0c, state:R) prio=0
"Clock" (TID:0x406c0088, sys_thread_t:0x413a1e0c, state:CW) prio=12
"main" (TID:0x406c00b0, sys_thread_t:0x81ad3c0, state:R) prio=5
*current thread*
java.lang.Runtime.loadLibrary(Runtime.java)
java.lang.System.loadLibrary(System.java)
HelloWorld.<clinit>(HelloWorld.java:13)
Monitor Cache Dump:
java.lang.Runtime@1080836216/1081192880: owner "main" (0x81ad3c0, 1
entry)
Registered Monitor Dump:
Thread queue lock: <unowned>
Name and type hash table lock: <unowned>
String intern lock: <unowned>
JNI pinning lock: <unowned>
JNI global reference lock: <unowned>
BinClass lock: <unowned>
Class loading lock: <unowned>
Java stack lock: <unowned>
Code rewrite lock: <unowned>
Heap lock: <unowned>
Has finalization queue lock: <unowned>
Finalize me queue lock: <unowned>
Dynamic loading lock: <unowned>
Monitor IO lock: <unowned>
Child death monitor: <unowned>
Event monitor: <unowned>
I/O monitor: <unowned>
Alarm monitor: <unowned>
Waiting to be notified:
"Clock" (0x413a1e0c)
Monitor registry: owner "main" (0x81ad3c0, 1 entry)
Thread Alarm Q:
Aborted (core dumped)
If there is any more data I can offer, please ask. I have moved 90 percent
of my development off of NT and onto Linux, this remains one of only a few
items left to port over.
(See attached file: HellWorldNative.c)(See attached file: HelloWorld.java)
(See attached file: HelloWorld.h)
Thank You
_________________
Steve Gee
Java Developer
Maxor National Pharmacies
Information Technologies
[EMAIL PROTECTED]
806.324.5540
www.maxor.com
806.324.5400
HellWorldNative.c
HelloWorld.java
HelloWorld.h