2012-06-26 114 views
0

嗨,大家好,我正在嘗試構建一個jni庫。構建在Windows正常工作,但在Linux Fedora的我面對它拋出一個錯誤,這樣Fedora的C代碼編譯問題

/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC 

我編譯代碼這樣一個問題

gcc -o libTest.so -shared -I/usr/java/jdk1.6.0_18/include -I/usr/java/jdk1.6.0_18/include/linux arrayUtil.c -static -lc 

誰能告訴我在哪兒我錯了嗎?

這是錯誤當我從JNI調用:

Instructions: (pc=0x00002aaaab22627a) 
0x00002aaaab22626a: 00 00 48 8b 44 24 18 4d 8b 7e 68 48 8b 5c 24 18 
0x00002aaaab22627a: 0f b6 10 48 0f be c2 41 f6 44 47 01 20 74 1c 48 

Stack: [0x000000004012b000,0x000000004022c000], sp=0x000000004022a660, free space=3fd0000000000000018k 
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) 
C [libc.so.6+0x3527a] 

[error occurred during error reporting (printing native stack), id 0xb] 

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) 
j com.utils.ArrayUtils.setup(Ljava/lang/String;)I+0 
j com.utils.ArrayUtils.init(Ljava/lang/String;)V+245 
j com.utils.ArrayUtils.main([Ljava/lang/String;)V+3 
v ~StubRoutines::call_stub 

--------------- P R O C E S S --------------- 

Java Threads: (=> current thread) 
    0x00002aaacff55000 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=5624, stack(0x0000000040832000,0x0000000040933000)] 
    0x00002aaacff52800 JavaThread "CompilerThread1" daemon [_thread_blocked, id=5623, stack(0x0000000040731000,0x0000000040832000)] 
    0x00002aaacff4d800 JavaThread "CompilerThread0" daemon [_thread_blocked, id=5622, stack(0x0000000040630000,0x0000000040731000)] 
    0x00002aaacff4b800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=5621, stack(0x000000004052f000,0x0000000040630000)] 
    0x00002aaacff28000 JavaThread "Finalizer" daemon [_thread_blocked, id=5620, stack(0x000000004042e000,0x000000004052f000)] 
    0x00002aaacff26000 JavaThread "Reference Handler" daemon [_thread_blocked, id=5619, stack(0x000000004032d000,0x000000004042e000)] 
=>0x0000000040111800 JavaThread "main" [_thread_in_native, id=5617, stack(0x000000004012b000,0x000000004022c000)] 

Other Threads: 
    0x00002aaacff21800 VMThread [stack: 0x000000004022c000,0x000000004032d000] [id=5618] 
    0x00002aaacff58000 WatcherThread [stack: 0x0000000040933000,0x0000000040a34000] [id=5625] 
+2

將'-'fPIC'添加到'gcc'命令中,如錯誤所示? – hmjd

+0

@hmjd:我確實嘗試過..但是我也得到了同樣的錯誤 – karthick

+0

@hmjd:我添加了-fpic像這樣gcc -o libTest.so -shared -fPIC -I ..可以嗎? – karthick

回答

1

從編輯命令刪除-static。不應該使用-static來構建共享對象,它用於構建靜態鏈接的可執行文件。

有關-static和鏈接器的更多信息,請查看here

+0

當我從java執行時,jni庫崩潰。 「已經由Java運行時環境中檢測到致命錯誤: # #SIGSEGV(0XB)在PC = 0x00002aaaab22627a,PID = 5593,TID = 1076017488 # #JRE版本:6.0_21-B06 #Java虛擬機:爪哇HotSpot(TM)64位服務器虛擬機(17.0-b16混合模式linux-amd64) – karthick

+0

您是否有可用的調用堆棧? –

+0

用調用堆棧更新了我的問題 – karthick