You are not logged in.

#1 2012-06-12 18:49:35

pausch
Member
Registered: 2012-01-08
Posts: 17

Compilation fails

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

#2 2012-06-12 18:53:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Compilation fails

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

#3 2012-06-12 22:54:28

pausch
Member
Registered: 2012-01-08
Posts: 17

Re: Compilation fails

Sorry I didnt knew that this is possible here...

Offline

Board footer

Powered by FluxBB