再请高手赐教:wrong ELF class: ELFCLASS64,十分感谢
编译.so库时若不用-fPIC,会编不过有错误如下:linux-z03057:~/workspace/CtoJavaTest # g++ -I/home/z03057/src/jdk1.6.0/include -I/home/z03057/src/jdk1.6.0/include/linux -o testdll.so -shared GetPid.c
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../x86_64-suse-linux/bin/ld: /tmp/ccq6CLL8.o: relocation R_X86_64_32 against `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
/tmp/ccq6CLL8.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
linux-z03057:~/workspace/CtoJavaTest #
linux-z03057:~/workspace/CtoJavaTest # javac GetPid.java
linux-z03057:~/workspace/CtoJavaTest # g++ -I/home/z03057/src/jdk1.6.0/include -I/home/z03057/src/jdk1.6.0/include/linux -w -fPIC -DPIC -o testdll.so -shared GetPid.c
运行时,出现以下错误:
linux-z03057:~/workspace/CtoJavaTest # java GetPid
/home/z03057/src/jdk1.6.0/jre/lib/i386/client:/home/z03057/src/jdk1.6.0/jre/lib/i386:/home/z03057/src/jdk1.6.0/jre/../lib/i386:.:/home/z03057/src/jdk1.6.0/jre/l ib/i386/client:/home/z03057/src/jdk1.6.0/jre/lib/i386:/lib:/usr/lib:/usr/java/packages/lib/i386:/lib:/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: /root/workspace/CtoJavaTest/testdll.so: /root/workspace/CtoJavaTest/testdll.so: wrong ELF class: ELFCLASS64
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at GetPid.<clinit>(GetPid.java:5)