簡體   English   中英

無法在Ubuntu中的Eclipse上生成jni

[英]Can't generate jni on Eclipse in Ubuntu

我遵循了教程,並且陷入了“全部創建”步驟。

我收到以下錯誤:

javah -classpath ../bin HelloJNI
gcc -m64 -Wl,--add-stdcall-alias -shared -o libHello.so HelloJNI.o
/usr/bin/ld: unrecognized option '--add-stdcall-alias'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
make: *** [libHello.so] Error 1

makefile看起來像這樣:

    # Define a variable for classpath
CLASS_PATH = ../bin

# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)

all : libHello.so

# $@ matches the target, $< matches the first dependancy
libHello.so : HelloJNI.o
    gcc -m64 -Wl,--add-stdcall-alias -shared -o $@ $<

# $@ matches the target, $< matches the first dependancy
HelloJNI.o : HelloJNI.c HelloJNI.h
    gcc -m64 -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" -c $< -o $@

# $* matches the target filename without the extension
HelloJNI.h : HelloJNI.class
    javah -classpath $(CLASS_PATH) $*

clean :
    rm HelloJNI.h HelloJNI.o libHello.so

我嘗試僅刪除--add-stdcall-alias,並得到:

gcc -m64 -Wl, -shared -o libHello.so HelloJNI.o
/usr/bin/ld: cannot find : No such file or directory
/usr/bin/ld: HelloJNI.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
HelloJNI.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [libHello.so] Error 1

我嘗試添加-fPIC,但出現了相同的錯誤。

我最終在終端上做了這樣的事情:

g++ -L/usr/lib/jni -fPIC -o libRecognizer.so -shared -Wl,-rpath, -I"/usr/lib/jvm/java-7-openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" facerec.cpp -lopencv_java249

所以這說明我需要鏈接庫libopencv_java249.so,並且能夠通過-L / usr / lib / jni-lopencv_java249來做到這一點。

“ / usr / lib / jni”是庫的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM