日期:2014-05-20 浏览次数:20945 次
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "GDA.h"
__attribute ((constructor)) void init_func(){
srand((unsigned)time(NULL));
printf("seed setted!\n");
}
JNIEXPORT jdoubleArray JNICALL
Java_GDA_genDoubleArray (JNIEnv *env, jclass clazz, jint length){
jdoubleArray gen_arr=env->NewDoubleArray(length);
if (gen_arr==NULL) {
fprintf(stderr, "cannot create double array!\n");
return NULL;
}
double tmp[length];
for (int i=0; i<length; i++)
tmp[i]=rand()/(double)RAND_MAX;
env->SetDoubleArrayRegion(gen_arr, 0, length,tmp);
return gen_arr;
}
hu@forhu-debian:~/Java code/JNI code/GenDoubleArr$ gcc -std=c99 -shared -o /home/hu/lib/libGenDoubleArr.so GDA.c
GDA.c: In function ‘Java_GDA_genDoubleArray’:
GDA.c:13:26: error: request for member ‘NewDoubleArray’ in something not a structure or union
GDA.c:21:5: error: request for member ‘SetDoubleArrayRegion’ in something not a structure or union