简体   繁体   English

无法在Ubuntu中的Eclipse上生成jni

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

I followed this tutorial and I got stuck at the "make all" step. 我遵循了教程,并且陷入了“全部创建”步骤。

I got the following error: 我收到以下错误:

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 looks like this: 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

I tried just removing --add-stdcall-alias, and got: 我尝试仅删除--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

I tried adding -fPIC, but I got the same error. 我尝试添加-fPIC,但出现了相同的错误。

I ended up doing something like this from the terminal: 我最终在终端上做了这样的事情:

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

so what this says is that I needed to link the library libopencv_java249.so and I was able to do that through -L/usr/lib/jni and -lopencv_java249 所以这说明我需要链接库libopencv_java249.so,并且能够通过-L / usr / lib / jni-lopencv_java249来做到这一点。

"/usr/lib/jni" is the path to the library. “ / usr / lib / jni”是库的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM