简体   繁体   English

JNI教程,无法加载库

[英]JNI Tutorial, cant'load library

i am trying to do this tutorial it's for JNI 我正在尝试为JNI做本教程

https://netbeans.org/kb/docs/cnd/beginning-jni-linux.html https://netbeans.org/kb/docs/cnd/beginning-jni-linux.html

i already did everything in there, but i am having this trouble 我已经在那里做了所有事情,但是我遇到了麻烦

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /home/usr/NetBeansProjects/JNIDemoCdl/dist/libJNIDemoCdl.so
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1846)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1061)
at jnidemojava.Main.<clinit>(Main.java:13)

Java Result: 1 Java结果:1

i am kind of stuck with JNI for a time now, and i could use some help, thanks 我现在有点呆在JNI上了,我可以使用一些帮助,谢谢

Make sure you have read/write permissions recursively over the directory structure and the lib file itself. 确保对目录结构和lib文件本身具有递归的读/写权限。

Try 尝试

sudo chmod ug+rwX -R /home/usr/NetBeansProjects/

That will add read/write permissions to the files and dirs, and execute permissions on directories and files that already have the execute flag for a user. 这将对文件和目录添加读/写权限,并对已经具有用户执行标志的目录和文件执行权限。

Hope this helps. 希望这可以帮助。

I never use mac but using windows i have faced same problem when i start working with jni. 我从不使用mac,但是使用Windows时,我开始使用jni时遇到了同样的问题。 With your problem it could be many things or one the created dll flag is not correct, make sure you have used correct command to create dll. 对于您的问题,可能是很多事情,或者创建的dll标志不正确,请确保您使用了正确的命令来创建dll。 i use the following command 我使用以下命令

gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -I"C:\Program Files\Java\jdk1.7.0\include" -I"C:\Program Files\Java\jdk1.7.0\include\win32" -shared -o Sample1.dll Sample1.cpp

for this i used mingw compiler. 为此,我使用了mingw编译器。

  • in windows dll file on mac this will so. 在Mac上的Windows dll文件中,它将如此。 i used the command System.loadlibrary("youLibraryNameWithoutExtensionAndPath") before this go to your project build path and expand jre and select native library then click brows and select folder where you put dll/so file and ok. 我使用了命令System.loadlibrary("youLibraryNameWithoutExtensionAndPath")然后转到项目构建路径并展开jre并选择本机库,然后单击眉毛并选择将dll / so文件放入其中的文件夹,然后单击确定。 now try to run your code. 现在尝试运行您的代码。 this will solve issue. 这将解决问题。

but if the dll/so file have dependent lib then you have to put all dll file in system32 folder (in windows) 但是,如果dll / so文件具有从属库,则必须将所有dll文件放入system32文件夹(在Windows中)

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

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