You are not logged in.
Pages: 1
Hi there
I am trying to compile a shared library with gcc for usage in java JNI. But the compilation of a simple HelloWorld program fails.
The compilation output is the following:
[paul@HP-ARCH JNIGeany]$ cc -shared -I/usr/lib/jvm/java-6-openjdk/include/ -I/usr/lib/jvm/java-6-openjdk/include/linux TestLib.cpp
/usr/bin/ld: /tmp/ccyze1mb.o: relocation R_X86_64_32 against `_ZSt4cout' can not be used when making a shared object; recompile with -fPIC
/tmp/ccyze1mb.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
The cpp file:
#include<iostream>
#include<jni.h>
#include "de_schaefer_jnitest_HelloWorld.h" // this header file was generated by javah
using namespace std;
JNIEXPORT void JNICALL Java_HelloWorld_Output(JNIEnv *env, jobject obj, jstring value)
{
cout << value;
}
int main() {
cout << "Test" << endl;
}
I am posting this stuff here because I think maybe ld works wrong...
Thanks...
Last edited by pausch (2012-06-12 22:54:04)
Offline
First, using code tags would make this much easier to read, and make you much more likely to get help.
Second, read error messages. Did you recompile with "-fPIC"?
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Sorry I didnt knew that this is possible here...
Offline
Pages: 1