2017-01-03 5 views
1

J'ai écrit le code C++ pour JNI puis construit la bibliothèque partagée. Cette bibliothèque partagée utilise la bibliothèque statique NTL. Mais il y a erreur suivante.JNI construit bibliothèque partagée en utilisant la bibliothèque statique NTL

configuration du compilateur et d'erreurs (Netbeans):

g++ -c -O2 -s -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux  
-I/usr/local/include/NTL -fPIC -MMD -MP -MF "build/Debug/GNU-Linux/ntl4java.o.d" 
-o build/Debug/GNU-Linux/ntl4java.o ntl4java.cpp 
mkdir -p dist/Debug/GNU-Linux 
g++  -o dist/Debug/GNU-Linux/libntl4java.so build/Debug/GNU-Linux/ntl4java.o -lgmp -lntl 
-shared -s -fPIC 
/usr/bin/ld: //usr/local/lib/libntl.a(lip.o): relocation R_X86_64_32 against .rodata.str1.1' 
can not be used when making a shared object; recompile with -fPIC 
//usr/local/lib/libntl.a: error adding symbols: Bad value 

ntl4java.cpp

#include <NTLmethod.h> 
#include <NTL/ZZ_pX.h> 
#include <string.h> 

using namespace std; 
using namespace NTL; 

JNIEXPORT jstring JNICALL Java_NTLmethod_mult(JNIEnv *env, jclass obj, jstring input) { 
    const char *str = env->GetStringUTFChars(input, 0); 
    ZZ p; 
    char c[128]; 
    strcpy(c, str); 
    env->ReleaseStringUTFChars(input, str); 

    return env->NewStringUTF(c); 
} 
int main(){ 
    return 0; 
} 

NTLmethod.h

#include <jni.h> 

#ifndef _Included_NTLmethod 
#define _Included_NTLmethod 
#ifdef __cplusplus 
extern "C" { 
#endif 

JNIEXPORT jstring JNICALL Java_NTLmethod_mult(JNIEnv *, jclass, jstring); 

#ifdef __cplusplus 
} 
#endif 
#endif 

Répondre

3

Parce que vous utilisez drapeau -fPIC pour votre bibliothèque partagée, vous devez également recompiler NTL avec l'option -fPIC.

+0

Ok, laissez-moi essayer :) – Maxr

+0

@Maxr Je veux dire que vous devez recompiler '/ usr/local/lib/libntl.a' avec -fPIC. Vous ne montrez pas comment vous avez compilé la bibliothèque libntl.a. – nadro

+0

OK Je vois, laissez-moi essayer ce ty :) – Maxr