O
os2
hi
i tried to improve performance on for some trigonometry calcule
i read
http://www.javaworld.com/javatips/jw-javatip141.html?
i do
tmp@linux:~/bench> echo $CLASSPATH
/usr/lib/j2sdk1.4.2_03:/home/tmp/bench/java
tmp@linux:~/bench> javac MathLib.java
tmp@linux:~/bench> javah -jni -o MathLib.h -classpath . MathLib
i have some error with this command..
tmp@linux:~/bench> gcc -I/usr/lib/j2sdk1.4.2_03
-I/usr/lib/j2sdk1.4.2_03/include/linux Math.c -o MathLib.so
/usr/lib/gcc-lib/i586-suse-linux/3.3.3/../../../crt1.o(.text+0x18): in
function « _start »:
.../sysdeps/i386/elf/start.S:98: undefined reference to `main'
/tmp/cc8K7UyJ.o(.text+0x1c): in function « Java_MathLib_sin »:
: undefined reference to `sin'
/tmp/cc8K7UyJ.o(.text+0x41): in function « Java_MathLib_cos »:
: undefined reference to `cos'
/tmp/cc8K7UyJ.o(.text+0x66): in function « Java_MathLib_sqrt »:
: undefined reference to `sqrt'
how to resolve that?
MathLib.java file
public class MathLib
{
public static native double sin(double radians);
public static native double cos(double radians);
public static native double sqrt(double value);
static
{
System.loadLibrary("MathLib");
}
}
Math.c file
#include <jni.h>
#include <math.h>
#include "MathLib.h"
#include <stdio.h>
JNIEXPORT jdouble JNICALL Java_MathLib_sin(JNIEnv *env, jobject obj,
jdouble value)
{
return(sin(value));
}
JNIEXPORT jdouble JNICALL Java_MathLib_cos(JNIEnv *env, jobject obj,
jdouble value)
{
return(cos(value));
}
JNIEXPORT jdouble JNICALL Java_MathLib_sqrt(JNIEnv *env, jobject obj,
jdouble value)
{
return(sqrt(value));
}
MathLib.h is generate automatically by javah....
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class MathLib */
#ifndef _Included_MathLib
#define _Included_MathLib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: MathLib
* Method: sin
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_MathLib_sin
(JNIEnv *, jclass, jdouble);
/*
* Class: MathLib
* Method: cos
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_MathLib_cos
(JNIEnv *, jclass, jdouble);
/*
* Class: MathLib
* Method: sqrt
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_MathLib_sqrt
(JNIEnv *, jclass, jdouble);
#ifdef __cplusplus
}
#endif
#endif
any idea?
i tried to improve performance on for some trigonometry calcule
i read
http://www.javaworld.com/javatips/jw-javatip141.html?
i do
tmp@linux:~/bench> echo $CLASSPATH
/usr/lib/j2sdk1.4.2_03:/home/tmp/bench/java
tmp@linux:~/bench> javac MathLib.java
tmp@linux:~/bench> javah -jni -o MathLib.h -classpath . MathLib
i have some error with this command..
tmp@linux:~/bench> gcc -I/usr/lib/j2sdk1.4.2_03
-I/usr/lib/j2sdk1.4.2_03/include/linux Math.c -o MathLib.so
/usr/lib/gcc-lib/i586-suse-linux/3.3.3/../../../crt1.o(.text+0x18): in
function « _start »:
.../sysdeps/i386/elf/start.S:98: undefined reference to `main'
/tmp/cc8K7UyJ.o(.text+0x1c): in function « Java_MathLib_sin »:
: undefined reference to `sin'
/tmp/cc8K7UyJ.o(.text+0x41): in function « Java_MathLib_cos »:
: undefined reference to `cos'
/tmp/cc8K7UyJ.o(.text+0x66): in function « Java_MathLib_sqrt »:
: undefined reference to `sqrt'
how to resolve that?
MathLib.java file
public class MathLib
{
public static native double sin(double radians);
public static native double cos(double radians);
public static native double sqrt(double value);
static
{
System.loadLibrary("MathLib");
}
}
Math.c file
#include <jni.h>
#include <math.h>
#include "MathLib.h"
#include <stdio.h>
JNIEXPORT jdouble JNICALL Java_MathLib_sin(JNIEnv *env, jobject obj,
jdouble value)
{
return(sin(value));
}
JNIEXPORT jdouble JNICALL Java_MathLib_cos(JNIEnv *env, jobject obj,
jdouble value)
{
return(cos(value));
}
JNIEXPORT jdouble JNICALL Java_MathLib_sqrt(JNIEnv *env, jobject obj,
jdouble value)
{
return(sqrt(value));
}
MathLib.h is generate automatically by javah....
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class MathLib */
#ifndef _Included_MathLib
#define _Included_MathLib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: MathLib
* Method: sin
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_MathLib_sin
(JNIEnv *, jclass, jdouble);
/*
* Class: MathLib
* Method: cos
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_MathLib_cos
(JNIEnv *, jclass, jdouble);
/*
* Class: MathLib
* Method: sqrt
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_MathLib_sqrt
(JNIEnv *, jclass, jdouble);
#ifdef __cplusplus
}
#endif
#endif
any idea?