|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2004
Messaggi: 581
|
[C&JNI]Undefined Reference To
Allora ragazzi ho un problema con un applicazione abbastanza complessa che mi ่ stata data da ampliare ma non riesco a farla partire...
Questa applicazione usa tramite jni un applicazione in c che poi tramite agneti mobili ่ possibile spostare sospendere ecc ecc, ora il mio problema risiede nella creazione della libreria .so che serve a far funzionare l'applicazione. E' stato creato un manager java che post compilazione ha dato un file .h e da questo ่ stata implementato un manager nativo.c Codice:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <jni.h>
#include <string.h>
#include <signal.h>
/* Header for class manager_NativeManager */
#ifndef _Included_manager_NativeManager
#define _Included_manager_NativeManager
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: manager_NativeManager
* Method: start_
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_manager_NativeManager_start_1
(JNIEnv *, jobject, jint);
/*
* Class: manager_NativeManager
* Method: suspend_
* Signature: (II)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_suspend_1
(JNIEnv *, jobject, jint, jint);
/*
* Class: manager_NativeManager
* Method: resume_
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_manager_NativeManager_resume_1
(JNIEnv *, jobject, jint);
/*
* Class: manager_NativeManager
* Method: stop_
* Signature: (II)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_stop_1
(JNIEnv *, jobject, jint, jint);
/*
* Class: manager_NativeManager
* Method: checkpoint_
* Signature: (II)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_checkpoint_1
(JNIEnv *, jobject, jint, jint);
/*
* Class: manager_NativeManager
* Method: split_
* Signature: (II)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_split_1
(JNIEnv *, jobject, jint, jint);
/*
* Class: manager_NativeManager
* Method: termination_
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_manager_NativeManager_termination_1
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
Codice:
#include <stdlib.h>
#include <stdio.h>
#include <jni.h>
#include <string.h>
#include <signal.h>
#include "manager_NativeManager.h"
#define STOP 1
#define SUSPEND 2
int status_pipe[5][2];
int events_pipe[5][2];
int myIndex=-1;
/* FUNZIONI CHE L'UTENTE DEVE RIDEFINIRE */
extern void start_();
extern void resume_();
extern void stop_(char status[]);
extern void suspend_(char status[]);
extern void checkpoint_(char status[]);
/* split_() se lasciato vuoto dall'utente effettua la checkpoint_() */
extern void split_(char status[]);
/* FINE FUNZIONI CHE L'UTENTE DEVE RIDEFINIRE */
/* handler per il segnale di STOP e SUSPEND */
void action(int sig){
if(sig==STOP){
char stname[30];
stop_(stname);
write(status_pipe[myIndex][1],stname,sizeof(stname));
close(status_pipe[myIndex][1]);
close(events_pipe[myIndex][1]);
}
else if(sig==SUSPEND){
char stname[30];
suspend_(stname);
write(status_pipe[myIndex][1],stname,sizeof(stname));
close(status_pipe[myIndex][1]);
close(events_pipe[myIndex][1]);
}
exit(sig);
}
/* handler per il segnale di CHEKPOINT e SPLIT */
void check_split_Handler(int sig){
if(sig==SIGRTMIN){
char stname[30];
checkpoint_(stname);
write(status_pipe[myIndex][1],stname,sizeof(stname));
signal(SIGRTMIN,check_split_Handler);
}
else if(sig==SIGRTMIN+1){
char stname[30],temp[30];
strcpy(temp,stname);
split_(stname);
if(strcmp(temp,stname)==0){
checkpoint_(stname);
}
write(status_pipe[myIndex][1],stname,sizeof(stname));
signal(SIGRTMIN+1,check_split_Handler);
}
}
/* handler per il segnale di terminazione del task */
void terminationHandler(int sig){
if(sig==SIGUSR1){
int terminated=1;
write(events_pipe[myIndex][1],&terminated,sizeof(int));
signal(SIGUSR1,terminationHandler);
}
}
/*
* Class: manager_NativeManager
* Method: start_
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_manager_NativeManager_start_1 (JNIEnv *env, jobject obj, jint index){
pipe(status_pipe[index]);
pipe(events_pipe[index]);
int pid=fork();
if(!pid){
signal(STOP,action);
signal(SUSPEND,action);
signal(SIGRTMIN,check_split_Handler);
signal(SIGRTMIN+1,check_split_Handler);
signal(SIGUSR1,terminationHandler);
myIndex=index;
close(status_pipe[index][0]);
close(events_pipe[index][0]);
start_();
}
else {
close(status_pipe[index][1]);
close(events_pipe[index][1]);
return pid;
}
}
/*
* Class: manager_NativeManager
* Method: resume_
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_manager_NativeManager_resume_1
(JNIEnv *env, jobject obj, jint index){
pipe(status_pipe[index]);
pipe(events_pipe[index]);
int pid=fork();
if(!pid){
signal(SUSPEND,action);
signal(STOP,action);
signal(SIGRTMIN,check_split_Handler);
signal(SIGRTMIN+1,check_split_Handler);
signal(SIGUSR1,terminationHandler);
myIndex=index;
close(status_pipe[index][0]);
close(events_pipe[index][0]);
resume_();
}
else {
close(status_pipe[index][1]);
close(events_pipe[index][1]);
return pid;
}
}
/*
* Class: manager_NativeManager
* Method: stop_
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_stop_1
(JNIEnv *env, jobject obj, jint app_pid, jint index){
if(app_pid>0){
kill(app_pid,STOP);
char status[30];
read(status_pipe[index][0],status,sizeof(status));
close(status_pipe[index][0]);
close(events_pipe[index][0]);
return (*env)->NewStringUTF(env,status);
}
}
/*
* Class: manager_NativeManager
* Method: suspend_
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_suspend_1
(JNIEnv *env, jobject obj, jint app_pid, jint index){
if(app_pid>0){
kill(app_pid,SUSPEND);
char status[30];
read(status_pipe[index][0],status,sizeof(status));
close(status_pipe[index][0]);
close(events_pipe[index][0]);
return (*env)->NewStringUTF(env,status);
}
}
/*
* Class: manager_NativeManager
* Method: checkpoint_
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_checkpoint_1
(JNIEnv *env, jobject obj, jint app_pid, jint index){
if(app_pid>0){
kill(app_pid,SIGRTMIN);
char status[30];
read(status_pipe[index][0],status,sizeof(status));
return (*env)->NewStringUTF(env,status);
}
}
/*
* Class: manager_NativeManager
* Method: split_
* Signature: (II)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_manager_NativeManager_split_1
(JNIEnv *env, jobject obj, jint app_pid, jint index){
if(app_pid>0){
kill(app_pid,SIGRTMIN+1);
char status[30];
read(status_pipe[index][0],status,sizeof(status));
return (*env)->NewStringUTF(env,status);
}
}
/*
* Class: manager_NativeManager
* Method: termination_
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_manager_NativeManager_termination_1
(JNIEnv *env, jobject obj, jint index){
int terminated=-1;
read(events_pipe[index][0],&terminated,sizeof(int));
return terminated;
}
Quando vado a compilare il manager nativo .c mi da questi errori: gcc NativeManager.c -I /usr/java/jdk1.6.0_16/include/ -I /usr/java/jdk1.6.0_16/include/linux/ Codice:
usr/lib/gcc/i586-manbo-linux-gnu/4.3.2/../../../crt1.o: In function `_start': /home/mandrake/rpm/BUILD/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main' /home/ermasto/tmp/ccRafG0k.o: In function `action': NativeManager.c:(.text+0x13): undefined reference to `stop_' NativeManager.c:(.text+0x80): undefined reference to `suspend_' /home/ermasto/tmp/ccRafG0k.o: In function `check_split_Handler': NativeManager.c:(.text+0x100): undefined reference to `checkpoint_' NativeManager.c:(.text+0x16c): undefined reference to `split_' NativeManager.c:(.text+0x18d): undefined reference to `checkpoint_' /home/ermasto/tmp/ccRafG0k.o: In function `Java_manager_NativeManager_start_1': NativeManager.c:(.text+0x2fe): undefined reference to `start_' /home/ermasto/tmp/ccRafG0k.o: In function `Java_manager_NativeManager_resume_1': NativeManager.c:(.text+0x417): undefined reference to `resume_' collect2: ld returned 1 exit status Grazie per l'aiuto
__________________
Toshiba M40-281 |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:20.



















