gcc compilation problem

Asked by snakeubuntu

hi ,
I'm compiling a program nativelib.c but i sot following problems here is the command i used and result i got

 COmmand:- root@ws40-man-lin:/home/manish.yadav/Desktop# gcc -o libnativelib.so -shared -Wl,-soname,libnative.so -I/usr/java/jdk1.6.0_20/include -I/usr/java/jdk1.6.0_20/include/linux nativelib.c -static -lc

RESULT :-/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

when i remove the -static flag from compiler then i got the following error

 Command :-root@ws40-man-lin:/home/manish.yadav/Desktop# gcc -o libnativelib.so -shared -Wl,-soname,libnative.so -I/usr/java/jdk1.6.0_20/include -I/usr/java/jdk1.6.0_20/include/linux nativelib.c -lc

 Result:-/usr/bin/ld: /tmp/ccTOK1y8.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccTOK1y8.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

i tried with _FPIC flag than tha result is following
Command :root@ws40-man-lin:/home/manish.yadav/Desktop# gcc -o libnativelib.so -shared -Wl,-soname,libnative.so -I/usr/java/jdk1.6.0_20/include -I/usr/java/jdk1.6.0_20/include/linux nativelib.c -FPIC
Result : /usr/bin/ld: /tmp/ccO4tElO.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccO4tElO.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

Can anyone tell what i'm doing wrong? what shoud i do to compile the pogram

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Best Manfred Hampl (m-hampl) said :
#1

Linux is highly case sensitive.
You were asked to recompile with -fPIC, but you added -FPIC.
Please try again with the correct flag added.

Revision history for this message
snakeubuntu (manish-yadav) said :
#2

Thanks Manfred Hampl, that solved my question.