我在使用 Java JNI 中的其他 .c 文件中的其他 C 函数调用 C 函数时遇到问题(不要介意我的代码中的一些法语单词,谢谢)。 C 语言代码运行良好。
这是我用来编译库的两行。我正在使用我在第二个库中使用的函数来编译我的第一个库。告诉我我是否做错了才能做到这一点:
gcc -fPIC -shared -I"$$JAVA_HOME/include"-I"$$JAVA_HOME/include/linux"-o 库/libfilemot.so ../IndexationTexte/fileMot.c
gcc -fPIC -shared -I"$$JAVA_HOME/include"-I"$$JAVA_HOME/include/linux"../IndexationTexte/indexationV1.c -L./Libraries/-l:libfilemot.so -o 库/libindexation .so
在我的 Java 类中,我有这个:
public class MoteurDeRecherche {
static {
try {
System.load("/home/aurelien/Documents/Projects/Projet_fil_rouge/noyau_c/JNI/Libraries/libfilemot.so");
System.load("/home/aurelien/Documents/Projects/Projet_fil_rouge/noyau_c/JNI/Libraries/libindexation.so");
}
catch(UnsatisfiedLinkError e) {
System.out.println("Erreur de chargement des librairies :\n" + e);
System.exit(1);
}
}
public static native void indexationTexte();
public static void main(String args[]) {
MoteurDeRecherche.indexationTexte();
}
}
但是我从成功编译的库中收到此错误:
Erreur de chargement des librairies :
java.lang.UnsatisfiedLinkError: /home/aurelien/Documents/Projects/Projet_fil_rouge/noyau_c/JNI/Libraries/libindexation.so: libfilemot.so: cannot open shared object file: No such file or directory
如果您想了解更多信息,请不要犹豫。再次感谢您。
最佳答案
native 链接器找不到您的共享对象。将包含您的 so 的文件夹添加到您的 LD_LIBRARY_PATH
中。
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:Libraries/
或者,您可以将其添加到本地库文件夹(通常为 /usr/local/lib
)并重新运行 ldconfig
。
关于java - JNI 调用 C 函数调用其他文件中的其他函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55200655/